Bugzilla – Attachment 193993 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: Throw exception on store of invalid marcxml
b576639.patch (text/plain), 2.86 KB, created by
Martin Renvoize (ashimema)
on 2026-02-26 13:45:38 UTC
(
hide
)
Description:
Bug 35104: Throw exception on store of invalid marcxml
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-02-26 13:45:38 UTC
Size:
2.86 KB
patch
obsolete
>From b5766396dad41340feb2ef8388ac5642379adeca 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: Throw exception on store of invalid marcxml > >This patch adds an exception Koha::Biblio::Metadata->store to prevent >erroneous characters in 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. > >Signed-off-by: Baptiste Bayche <baptiste.bayche@inlibro.com> >Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Sponsored-by: OpenFifth >--- > C4/Biblio.pm | 2 -- > Koha/Biblio/Metadata.pm | 36 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+), 2 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 1f1f897e544..aaee18aebfb 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -88,7 +88,6 @@ use C4::Charset qw( > nsb_clean > SetMarcUnicodeFlag > SetUTF8Flag >- StripNonXmlChars > ); > use C4::Languages; > use C4::Linker; >@@ -2315,7 +2314,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, ); > } > >diff --git a/Koha/Biblio/Metadata.pm b/Koha/Biblio/Metadata.pm >index 62639b7815b..926f5d85bc5 100644 >--- a/Koha/Biblio/Metadata.pm >+++ b/Koha/Biblio/Metadata.pm >@@ -40,6 +40,42 @@ Koha::Metadata - Koha Metadata Object class > > =cut > >+=head3 store >+ >+Metadata specific store method to catch errant characters prior >+to committing to the database. >+ >+=cut >+ >+sub store { >+ my $self = shift; >+ >+ # Check marcxml will roundtrip >+ if ( $self->format eq 'marcxml' ) { >+ >+ my $marcxml = eval { >+ MARC::Record::new_from_xml( >+ $self->metadata, 'UTF-8', >+ $self->schema >+ ); >+ }; >+ my $marcxml_error = $@; >+ chomp $marcxml_error; >+ unless ($marcxml) { >+ warn $marcxml_error; >+ Koha::Exceptions::Metadata::Invalid->throw( >+ id => $self->id, >+ biblionumber => $self->biblionumber, >+ format => $self->format, >+ schema => $self->schema, >+ decoding_error => $marcxml_error, >+ ); >+ } >+ } >+ >+ return $self->SUPER::store; >+} >+ > =head3 record > > my $record = $metadata->record; >-- >2.53.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
|
176820
|
176821
|
176850
|
176851
|
176852
|
176860
|
193985
|
193986
|
193987
|
193988
|
193989
|
193990
|
193991
|
193992
|
193993
|
193994
|
193995
|
193996
|
193997
|
193998
|
193999
|
194000
|
194001
|
194004
|
194005
|
194006
|
194007
|
194008
|
194009
|
194010
|
194011
|
194012
|
194013