From 7f7dfa0a11dd5d983deca2c18715b5126a11b12c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 11 Aug 2009 10:46:20 -0400 Subject: [PATCH] bug 3520: fix crash when adding or editing items Fix the following crash when adding or editing an item record in the staff interface: Can't call method "append_fields" on an undefined value at /usr/local/share/perl/5.10.0/MARC/File/SAX.pm line 92. at /usr/local/share/perl/5.10.0/MARC/File/SAX.pm line 92 This crash appears only if a version of MARC::File::XML greater than 0.88 is installed, and was triggered by C4::Biblio::TransformHtmlToXml() failing to create a valid MARCXML blob, which must include a element. This patch also fixes the indicator values generated by TransformHtmlToXml(), setting them to " " instead of "" when no indicator value is supplied. Signed-off-by: Galen Charlton --- C4/Biblio.pm | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index a7c66f94a6..569e09e4b8 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1624,6 +1624,7 @@ $auth_type contains : sub TransformHtmlToXml { my ( $tags, $subfields, $values, $indicator, $ind_tag, $auth_type ) = @_; my $xml = MARC::File::XML::header('UTF-8'); + $xml .= "\n"; $auth_type = C4::Context->preference('marcflavour') unless $auth_type; MARC::File::XML->default_record_format($auth_type); # in UNIMARC, field 100 contains the encoding @@ -1670,10 +1671,8 @@ sub TransformHtmlToXml { warn "Indicator in @$tags[$i] is empty"; $ind2 = " "; } - $xml .= -"\n"; - $xml .= -"@$values[$i]\n"; + $xml .= "\n"; + $xml .= "@$values[$i]\n"; $first = 0; } else { @@ -1691,17 +1690,16 @@ sub TransformHtmlToXml { # rest of the fixed fields } elsif ( @$tags[$i] < 10 ) { - $xml .= -"@$values[$i]\n"; + $xml .= "@$values[$i]\n"; $first = 1; } else { my $ind1 = substr( @$indicator[$j], 0, 1 ); my $ind2 = substr( @$indicator[$j], 1, 1 ); - $xml .= -"\n"; - $xml .= -"@$values[$i]\n"; + $ind1 = " " if !defined($ind2) or $ind2 eq ""; + $ind2 = " " if !defined($ind2) or $ind2 eq ""; + $xml .= "\n"; + $xml .= "@$values[$i]\n"; $first = 0; } } @@ -1714,12 +1712,12 @@ sub TransformHtmlToXml { if ($first) { my $ind1 = substr( @$indicator[$j], 0, 1 ); my $ind2 = substr( @$indicator[$j], 1, 1 ); - $xml .= -"\n"; + $ind1 = " " if !defined($ind2) or $ind2 eq ""; + $ind2 = " " if !defined($ind2) or $ind2 eq ""; + $xml .= "\n"; $first = 0; } - $xml .= -"@$values[$i]\n"; + $xml .= "@$values[$i]\n"; } } $prevtag = @$tags[$i]; @@ -1737,6 +1735,7 @@ sub TransformHtmlToXml { $xml .= "$string\n"; $xml .= "\n"; } + $xml .= "\n"; $xml .= MARC::File::XML::footer(); return $xml; } -- 2.39.5