r1536@llin: dpavlin | 2007-11-04 17:47:03 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Nov 2007 16:47:03 +0000 (16:47 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Nov 2007 16:47:03 +0000 (16:47 +0000)
 better handle invalid XML files

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@998 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Input/XML.pm
t/2-input-xml.t

index e989023..e9b9f56 100644 (file)
@@ -114,14 +114,21 @@ sub fetch_rec {
 
        my $log = $self->_get_logger();
 
-       our $xml = XMLin(
-               $path,
-#              ForceArray => 1,
-#              ForceContent => 1,
-               KeepRoot => 1,
-#              SuppressEmpty => 1, # '' undef
-
-       ) || $log->logdie("can't open $path: $!");
+       our $xml;
+       eval {
+               $xml = XMLin(
+                       $path,
+#                      ForceArray => 1,
+#                      ForceContent => 1,
+                       KeepRoot => 1,
+#                      SuppressEmpty => 1, # '' undef
+               ) || die "can't open $path: $!";
+       };
+
+       if ( $@ ) {
+               $log->error("$@");
+               return;
+       }
 
        $log->debug("fetch_rec( $mfn ) => $path => xml is ",sub { dump($xml) });
 
index 2dae39f..efba79e 100755 (executable)
@@ -3,7 +3,7 @@
 use strict;
 use blib;
 
-use Test::More tests => 18;
+use Test::More tests => 24;
 
 BEGIN {
 use_ok( 'WebPAC::Test' );
@@ -29,10 +29,10 @@ ok(my $size = $input->size, "size");
 
 foreach my $mfn ( 1 ... $size ) {
        my $rec = $input->fetch;
-       if ($mfn <= 10 || $mfn == 20) {
-               ok($rec, "fetch $mfn");
+       if ( $mfn >= 7 ) {
+               ok(! $rec, "error $mfn");
        } else {
-               ok(! $rec, "empty $mfn");
+               ok($rec, "fetch $mfn");
        }
 
        cmp_ok($input->pos, '==', $mfn, "pos $mfn");