Bug 35142: (follow-up) Fix detail page crash with invalid metadata

The staff catalogue detail page called $biblio->normalized_upc,
normalized_ean, and normalized_oclc unconditionally. These methods
go through metadata_extractor which calls $biblio->metadata->record
internally, re-fetching the (corrupt) metadata from the DB and
ignoring the already-sanitized $marc_record.

When a record has invalid MARCXML, this causes an unhandled exception
instead of displaying the 'biberror' warning.

Fix: use the Extractor directly with the already-recovered
$marc_record (which was sanitized via StripNonXmlChars), and guard
the block with a check that $marc_record is defined.

Test plan:
1. Apply patch
2. Run:
   $ ktd --proxy --selenium up -d
   $ ktd --wait-ready 120
   $ ktd --shell
   k$ prove t/db_dependent/selenium/regressions.t
=> SUCCESS: Tests pass (including 'detail page must not explode')
3. Sign off :-D

Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Tomás Cohen Arazi 2026-08-25 10:52:53 -03:00 committed by Pedro Amorim
parent 481e170da1
commit 1839189b1c
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 9 additions and 4 deletions

View File

@ -43,6 +43,7 @@ use Koha::AuthorisedValues;
use Koha::Biblios;
use Koha::Biblio::ItemGroup::Items;
use Koha::Biblio::ItemGroups;
use Koha::Biblio::Metadata::Extractor;
use Koha::BiblioFrameworks;
use Koha::Controller::Catalogue;
use Koha::CoverImages;
@ -166,10 +167,14 @@ $template->param( ocoins => !$invalid_marc_record ? $biblio->get_coins : undef )
# some useful variables for enhanced content;
# in each case, we're grabbing the first value we find in
# the record and normalizing it
my $upc = $biblio->normalized_upc;
my $ean = $biblio->normalized_ean;
my $oclc = $biblio->normalized_oclc;
my $isbn = GetNormalizedISBN( undef, $marc_record, $marcflavour );
my ( $upc, $ean, $oclc, $isbn );
if ($marc_record) {
my $extractor = Koha::Biblio::Metadata::Extractor->new( { metadata => $marc_record } );
$upc = $extractor->get_normalized_upc;
$ean = $extractor->get_normalized_ean;
$oclc = $extractor->get_normalized_oclc;
$isbn = GetNormalizedISBN( undef, $marc_record, $marcflavour );
}
my $content_identifier_exists;
if ( $isbn or $ean or $oclc or $upc ) {
$content_identifier_exists = 1;