Bugzilla – Attachment 159615 Details for
Bug 35104
We should warn when attempting to save MARC records that contain characters invalid in XML
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35104: [Alternative] Throw exception on store of invalid marcxml
Bug-35104-Alternative-Throw-exception-on-store-of-.patch (text/plain), 3.08 KB, created by
Martin Renvoize (ashimema)
on 2023-12-06 11:53:23 UTC
(
hide
)
Description:
Bug 35104: [Alternative] Throw exception on store of invalid marcxml
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-12-06 11:53:23 UTC
Size:
3.08 KB
patch
obsolete
>From 941369d0b3f545c90573deb943ae50d6304a77cc Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 6 Dec 2023 11:49:43 +0000 >Subject: [PATCH] Bug 35104: [Alternative] Throw exception on store of invalid > marcxml > >This patch adds an exception into ModBilioMarc to prevent erronious >marcxml being stored into the database. We also remove the cleanup of >such characters from TransformHtmlToMarc as introduced by bug 34549. > >This should result in there being no way, outside of direct database >manipulation, of getting forbidden characters into our marcxml store. > >We'll need to work through the codebase to catch the exception thrown to >give the end user the oportunities to act on the error and fix the data >at source. >--- > C4/Biblio.pm | 24 +++++++++++++++++++++--- > 1 file changed, 21 insertions(+), 3 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index ab895b25753..2e0d97ee185 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -93,7 +93,6 @@ use C4::Charset qw( > nsb_clean > SetMarcUnicodeFlag > SetUTF8Flag >- StripNonXmlChars > ); > use C4::Languages; > use C4::Linker; >@@ -107,6 +106,7 @@ use Koha::Authority::Types; > use Koha::Acquisition::Currencies; > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > use Koha::Biblio::Metadatas; >+use Koha::Exceptions::Metadata; > use Koha::Holds; > use Koha::ItemTypes; > use Koha::MarcOverlayRules; >@@ -2248,7 +2248,6 @@ sub TransformHtmlToMarc { > ; > # between 001 and 009 (included) > } elsif ( $fval ne '' ) { >- $fval = StripNonXmlChars($fval); #Strip out any non-XML characters like control characters > $newfield = MARC::Field->new( $tag, $fval, ); > } > >@@ -2270,7 +2269,6 @@ sub TransformHtmlToMarc { > $newfield->add_subfields( $fkey => $fval); > } > elsif($fval ne '') { >- $fval = StripNonXmlChars($fval); #Strip out any non-XML characters like control characters > $newfield = MARC::Field->new( $tag, $ind1, $ind2, $fkey => $fval ); > } > $j += 2; >@@ -2867,6 +2865,26 @@ sub ModBiblioMarc { > Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername); > } > >+ # Check marcxml roundtrip >+ my $marcxml = eval { >+ MARC::Record::new_from_xml( >+ $record->as_xml_record($encoding), 'UTF-8', >+ C4::Context->preference('marcflavour') >+ ); >+ }; >+ my $marcxml_error = $@; >+ chomp $marcxml_error; >+ unless ($marcxml) { >+ warn $marcxml_error; >+ Koha::Exceptions::Metadata::Invalid->throw( >+ id => $m_rs->id, >+ biblionumber => $m_rs->biblionumber, >+ format => 'marcxml', >+ schema => C4::Context->preference('marcflavour'), >+ decoding_error => $marcxml_error, >+ ); >+ } >+ > $m_rs->metadata( $record->as_xml_record($encoding) ); > $m_rs->store; > >-- >2.43.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35104
:
157625
|
157627
|
157628
|
157642
|
159615
|
159620
|
159621
|
159630
|
159810
|
159811
|
159812
|
159813
|
166431
|
173145
|
173146