Bug 13082: fix to prevent adding of invalid records in marc file
authorStéphane Delaune <stephane.delaune@biblibre.com>
Tue, 21 Oct 2014 16:05:18 +0000 (18:05 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Fri, 14 Nov 2014 14:47:00 +0000 (11:47 -0300)
Test:

1. Edit record, add 100.000 chars text to 500a

2. xml export produce the record,

3. mrc export do not produce the record, warning on log export.pl:
   Record length of 111000 is larger than the MARC spec allows (99999
   bytes). at /usr/share/perl5/MARC/File/USMARC.pm line 314.  record
   (number 139489) is invalid and therefore not exported because its
   reopening generates warnings above at...

Signed-off-by: Frederic Demians <f.demians@tamil.fr>
I confirm that exporting biblio records larger than 10000 characters in
ISO2709 produces invalid files. After applying this patch, the culprit
record (too large, but also other inconsistencies preventing record
parsing with MARC::File::USMARC) is not exported anymore. A warning is
produced in Koha Apache log file. Warnings to the user on WUI would be
better, but it isn't the case yet, so it isn't a regression.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
I agree that a visible warning/result message in the staff interface
would be nice, but this works as described.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
tools/export.pl

index 658aef7..98b9ef9 100755 (executable)
@@ -416,9 +416,10 @@ if ( $op eq "export" ) {
                     print "\n";
                 }
                 else {
-                    my (@result_build_tag) = MARC::File::USMARC::_build_tag_directory($record);
-                    if ($result_build_tag[2] > 99999) {
-                        warn "record (number $recordid) length ".$result_build_tag[2]." is larger than the MARC spec allows (99999 bytes)";
+                    my $errorcount_on_decode = eval { scalar(MARC::File::USMARC->decode( $record->as_usmarc )->warnings()) };
+                    if ($errorcount_on_decode or $@){
+                        warn $@ if $@;
+                        warn "record (number $recordid) is invalid and therefore not exported because its reopening generates warnings above";
                         next;
                     }
                     print $record->as_usmarc();