From 1839189b1cf54ea6ebd85b0cfc619fbc6cd4e2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Tue, 25 Aug 2026 10:52:53 -0300 Subject: [PATCH] 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 --- catalogue/detail.pl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 93953e6dad..7aae3d53e3 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -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;