From e0f1beb40ee59fda4bc8d5e0944e76c6cb22e03e 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 Signed-off-by: Henri-Damien LAURENT --- C4/Biblio.pm | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 74e1acef09..ba6d62cfcd 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1622,6 +1622,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 @@ -1668,10 +1669,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 { @@ -1689,17 +1688,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; } } @@ -1712,12 +1710,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]; @@ -1735,6 +1733,7 @@ sub TransformHtmlToXml { $xml .= "$string\n"; $xml .= "\n"; } + $xml .= "\n"; $xml .= MARC::File::XML::footer(); return $xml; } -- 2.39.5