Some defensive coding in NCIP::ILS.pm.
authorJason Stephenson <jason@sigio.com>
Thu, 30 Jul 2015 13:38:55 +0000 (09:38 -0400)
committerJason Stephenson <jason@sigio.com>
Thu, 30 Jul 2015 13:38:55 +0000 (09:38 -0400)
XML::LibXML::Simple will return {} for an empty field.  We need to
check this on barcode input, at least, and undef the variable.  This
is done in the base class find_user_barcode and find_item_barcode
methods.

Signed-off-by: Jason Stephenson <jason@sigio.com>
lib/NCIP/ILS.pm

index ef64d93..6e654c2 100644 (file)
@@ -348,6 +348,9 @@ sub find_user_barcode {
         }
     }
 
+    # Because XML::LibXML::Simple returns {} for empty text values.
+    undef($barcode) if (ref($barcode) eq 'HASH' && !%{$barcode});
+
     return (wantarray) ? ($barcode, $field) : $barcode;
 }
 
@@ -386,6 +389,8 @@ sub find_item_barcode {
                 next unless ($input->{ItemIdentifierType} =~ /barcode/i);
             }
             $barcode = $input->{ItemIdentifierValue};
+            # Because XML::LibXML::Simple returns {} for empty text values.
+            undef($barcode) if (ref($barcode) eq 'HASH' && !%{$barcode});
             last if ($barcode);
         }
     }