bug 2235: fix various data-corrupting bugs in MARC editor
authorGalen Charlton <galen.charlton@liblime.com>
Tue, 10 Jun 2008 16:05:48 +0000 (11:05 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 10 Jun 2008 17:59:44 +0000 (12:59 -0500)
1. Non-ASCII characters in the 942$h (biblioitems.cn_class)
   would cause an edit to fail and lead to a corrupt MARC record in
   biblioitems.marc and biblioitems.marcxml.  Fixed by
   turning on Perl's UTF-8 flag for MARC tag parameters
   processed by C4::Biblio::TransformHtmlToMarc

2. Do not add empty 006 and 007 fields if the corresponding
   input fields are blank.

3. Make it possible to save '0' as a valid subfield
   value.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Biblio.pm

index 8649af3..7b2dbd2 100755 (executable)
@@ -1487,7 +1487,21 @@ sub TransformHtmlToXml {
 sub TransformHtmlToMarc {
     my $params = shift;
     my $cgi    = shift;
-    
+   
+    # explicitly turn on the UTF-8 flag for all
+    # 'tag_' parameters to avoid incorrect character
+    # conversion later on
+    my $cgi_params = $cgi->Vars;
+    foreach my $param_name (keys %$cgi_params) {
+        if ($param_name =~ /^tag_/) {
+            my $param_value = $cgi_params->{$param_name};
+            if (utf8::decode($param_value)) {
+                $cgi_params->{$param_name} = $param_value;
+            } 
+            # FIXME - need to do something if string is not valid UTF-8
+        }
+    }
+   
     # creating a new record
     my $record  = MARC::Record->new();
     my $i=0;
@@ -1527,7 +1541,7 @@ sub TransformHtmlToMarc {
                 if ($tag eq '000' ) {
                     $record->leader($cgi->param($params->[$j+1])) if length($cgi->param($params->[$j+1]))==24;
     # between 001 and 009 (included)
-                } else {
+                } elsif ($cgi->param($params->[$j+1]) ne '') {
                     $newfield = MARC::Field->new(
                         $tag,
                         $cgi->param($params->[$j+1]),
@@ -1538,13 +1552,13 @@ sub TransformHtmlToMarc {
                 while($params->[$j] =~ /_code_/){ # browse all it's subfield
                     my $inner_param = $params->[$j];
                     if ($newfield){
-                        if($cgi->param($params->[$j+1])){  # only if there is a value (code => value)
+                        if($cgi->param($params->[$j+1]) ne ''){  # only if there is a value (code => value)
                             $newfield->add_subfields(
                                 $cgi->param($inner_param) => $cgi->param($params->[$j+1])
                             );
                         }
                     } else {
-                        if ( $cgi->param($params->[$j+1]) ) { # creating only if there is a value (code => value)
+                        if ( $cgi->param($params->[$j+1]) ne '' ) { # creating only if there is a value (code => value)
                             $newfield = MARC::Field->new(
                                 $tag,
                                 ''.$ind1,