Commits

Shlomi Fish  committed 3c73925

Apply patch: make domain work for unknown domains.

- Apply 0003-XML-LibXML-Error-make-domain-work-for-unknown-domain.patch
from https://rt.cpan.org/Public/Bug/Display.html?id=68575 - handle
unknown domains.
-- Applied by SHLOMIF.
-- Thanks to Aaron Crane.

  • Participants
  • Parent commits a9b6714

Comments (0)

Files changed (3)

       AUTOLOAD completely.
         -- Applied by SHLOMIF.
         -- Thanks to Aaron Crane.
+    - Apply 0003-XML-LibXML-Error-make-domain-work-for-unknown-domain.patch
+      from https://rt.cpan.org/Public/Bug/Display.html?id=68575 - handle
+      unknown domains.
+        -- Applied by SHLOMIF.
+        -- Thanks to Aaron Crane.
+
 
 1.70
    - various fixes and improvements in the documentation

File lib/XML/LibXML/Error.pm

 sub domain {
     my ($self)=@_;
     return undef unless ref($self);
-    return $error_domains[$self->{domain}];
+    my $domain = $self->{domain};
+    # Newer versions of libxml2 might yield errors in domains that aren't
+    # listed above.  Invent something reasonable in that case.
+    return $domain < @error_domains ? $error_domains[$domain] : "domain_$domain";
 }
 
 sub as_string {
         $where.=": element ".$self->{nodename};
     }
     $msg.=$where.": " if $where ne "";
-    $msg.=$error_domains[$self->{domain}]." ".$level." :";
+    $msg.=$self->domain." ".$level." :";
     my $str=$self->{message}||"";
     chomp($str);
     $msg.=" ".$str."\n";

File t/60struct_error.t

 BEGIN { 
     use XML::LibXML;
     if ( XML::LibXML::HAVE_STRUCT_ERRORS() ) {
-        plan tests => 6;
+        plan tests => 8;
     } else {
         plan tests => 1;
     }
     fail() for 1..3;
   }
 
+  my $fake_err = XML::LibXML::Error->new('fake error');
+  my $domain_num = @XML::LibXML::Error::error_domains;      # too big
+  $fake_err->{domain} = $domain_num;                        # white-box test
+  ok($fake_err->domain, "domain_$domain_num",
+     '$err->domain is reasonable on unknown domain');
+  {
+      my $warnings = 0;
+      local $SIG{__WARN__} = sub { $warnings++; warn "@_\n" };
+      my $s = $fake_err->as_string;
+      ok($warnings, 0,
+         'no warnings when stringifying unknown-domain error');
+  }
 } # HAVE_STRUCT_ERRORS