Bug 24827: Specify UTF-8 as encoding in new_from_xml()
authorAndreas Roussos <a.roussos@dataly.gr>
Sun, 15 Mar 2020 07:43:25 +0000 (08:43 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 16 Mar 2020 14:45:47 +0000 (14:45 +0000)
The MARC preview of staged records fails when a staged record contains
items with UTF-8 characters (see attached screenshots). That's because
in EmbedItemsInImportBiblio() the call to MARC::Record->new_from_xml()
does not explicitly specify 'UTF-8' as the optional encoding to use.

This patch fixes that.

Test plan (in a MARC21 instance):
0) Stage for import the test record attached to this bug report (make
   sure that 'Check for embedded item record data?' is set to 'Yes'),
   then go to Home > Tools > Manage staged MARC records and click on
   the filename you've just staged.
1) In the 'Citation' column, click on the hyperlink to launch the MARC
   preview -- notice how it fails to produce any output apart from the
   modal heading.
2) Apply the patch, and restart Plack if necessary.
3) Re-launch the MARC preview: this time the output should include the
   whole record, including the embedded item data in field 952.
4) Run the unit tests to ensure nothing was broken inadvertently:
   $ prove t
   $ prove xt

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/ImportBatch.pm
Koha/BiblioUtils/Iterator.pm
t/db_dependent/Koha/Z3950Responder/GenericSession.t
t/db_dependent/Koha/Z3950Responder/ZebraSession.t

index 11889fd..eaf8b55 100644 (file)
@@ -204,7 +204,7 @@ sub EmbedItemsInImportBiblio {
     |, { Slice => {} }, $import_record_id );
     my @item_fields;
     for my $import_item ( @$import_items ) {
-        my $item_marc = MARC::Record::new_from_xml($import_item->{marcxml});
+        my $item_marc = MARC::Record::new_from_xml($import_item->{marcxml}, 'UTF-8');
         push @item_fields, $item_marc->field($itemtag);
     }
     $record->append_fields(@item_fields);
index 1c8c9d3..f8a4e41 100644 (file)
@@ -95,7 +95,7 @@ sub next {
     return if !$row;
     my $marcxml = C4::Biblio::GetXmlBiblio( $row->get_column('biblionumber') );
     if ( $marcxml ) {
-        $marc = MARC::Record->new_from_xml( $marcxml );
+        $marc = MARC::Record->new_from_xml( $marcxml, 'UTF-8' );
     }
     else {
         confess "No marcxml column returned in the request.";
index fd52dde..f888b02 100644 (file)
@@ -109,11 +109,11 @@ subtest 'test_search' => sub {
 
     is($rs->size(), 2, 'Two results returned');
 
-    my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw());
+    my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw(), 'UTF-8');
     ok($returned1, 'Record 1 returned as MARCXML');
     is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly');
 
-    my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw());
+    my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw(), 'UTF-8');
     ok($returned2, 'Record 2 returned as MARCXML');
     is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly');
 
@@ -140,11 +140,11 @@ subtest 'test_search' => sub {
     my @records = $nodes[0]->getElementsByTagNameNS($marc_ns, 'record');
     is(scalar(@records), 2, 'Two results returned');
 
-    $returned1 = MARC::Record->new_from_xml($records[0]->toString());
+    $returned1 = MARC::Record->new_from_xml($records[0]->toString(), 'UTF-8');
     ok($returned1, 'Record 1 returned as MARCXML');
     is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly');
 
-    $returned2= MARC::Record->new_from_xml($records[1]->toString());
+    $returned2= MARC::Record->new_from_xml($records[1]->toString(), 'UTF-8');
     ok($returned2, 'Record 2 returned as MARCXML');
     is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly');
 
index 4ba1a60..3de0d2e 100644 (file)
@@ -106,11 +106,11 @@ subtest 'test_search' => sub {
 
     is($rs->size(), 2, 'Two results returned');
 
-    my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw());
+    my $returned1 = MARC::Record->new_from_xml($rs->record(0)->raw(), 'UTF-8');
     ok ($returned1, 'Record 1 returned as MARCXML');
     is($returned1->as_xml, $marc_record_1->as_xml, 'Record 1 returned properly');
 
-    my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw());
+    my $returned2= MARC::Record->new_from_xml($rs->record(1)->raw(), 'UTF-8');
     ok ($returned2, 'Record 2 returned as MARCXML');
     is($returned2->as_xml, $marc_record_2->as_xml, 'Record 2 returned properly');