Commits

Shlomi Fish committed ac1a4b7

Fix https://rt.cpan.org/Ticket/Display.html?id=58024 .

recover_silently was not properly handled.

  • Participants
  • Parent commits ed97737

Comments (0)

Files changed (4)

     lib/XML/LibXML/NodeList.pm :
         - https://rt.cpan.org/Ticket/Display.html?id=57737
         - Thanks to MSCHWERN .
-    
+    - Fix https://rt.cpan.org/Ticket/Display.html?id=58024 :
+        - <<< In XML::LibXML, warnings are not suppressed when specifying the 
+        recover() or recover_silently() flags as per the following excerpt from
+        the manpage: >>>
+        - Now XML-LibXML requires perl-5.8.x (to print to a buffer trick.).
+
 1.76            Thu Jun 30 20:58:46 IDT 2011
     - Cleaned up t/28new_callbacks_multiple.t - convert to a Counter
      and Stacker class.
   my $flags = 0;
   $flags |=     1 if exists $opts->{recover} ? $opts->{recover} : $self->recover;
   $flags |=    32 if exists $opts->{suppress_errors} ? $opts->{suppress_errors} : $self->get_option('suppress_errors');
+  # This is to fix https://rt.cpan.org/Ticket/Display.html?id=58024 :
+  # <quote> 
+  # In XML::LibXML, warnings are not suppressed when specifying the recover
+  # or recover_silently flags as per the following excerpt from the manpage:
+  # </quote>
+  if ($self->recover_silently)
+  {
+      $flags |= 32;
+  }
   $flags |=    64 if $opts->{suppress_warnings};
   $flags |=   128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser;
   $flags |=   256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks;
 use strict;
 use warnings;
 
+require 5.008;
+
 use vars qw/$DEVNULL $is_Win32 $extralibdir $skipsaxinstall/;
 
-BEGIN {
-  if ($] < 5.006_001) {
-    warn "\nSorry, at least Perl 5.6.1 is required for this module!\n\n";
-    exit;
-  }
-}
-
 use ExtUtils::MakeMaker;
 use Config;
 use Symbol;

File t/49_load_html.t

  
 use strict;
 use warnings;
+use utf8;
 
 use lib './t/lib';
 use TestHelpers;
 
-use Test::More tests => 1;
+use Test::More tests => 3;
 
 use XML::LibXML;
 
     );
 }
 
+{
+    # These are tests for https://rt.cpan.org/Ticket/Display.html?id=58024 :
+    # <<<
+    # In XML::LibXML, warnings are not suppressed when specifying the recover
+    # or recover_silently flags as per the following excerpt from the manpage:
+    # >>>
+
+    my $txt = <<'EOS';
+<div>
+<a href="milu?a=eins&b=zwei"> ampersand not URL-encoded </a>
+<!-- HTML parser error : htmlParseEntityRef: expecting ';' -->
+</div>
+EOS
+
+    {
+        my $buf = '';
+        open my $fh, '>', \$buf;
+        # redirect STDERR there
+        local *STDERR = $fh;
+
+        XML::LibXML->new(recover => 1)->load_html( string => $txt );
+        close($fh);
+
+        # TEST
+        like ($buf, qr/htmlParseEntityRef:/, 'warning emitted');
+    }
+    {
+        my $buf = '';
+        open my $fh, '>', \$buf;
+        local *STDERR = $fh;
+        XML::LibXML->new(recover => 2)->load_html( string => $txt );
+        close($fh);
+        # TEST
+        is ($buf, '', 'No warning emitted.');
+    }
+}
 
 =head1 COPYRIGHT & LICENSE