Commits

Shlomi Fish  committed 9386490

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

Thanks to Neil Wellnhofer for the report.

  • Participants
  • Parent commits 07c9ea9

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
+2.0112
+    - Fix https://rt.cpan.org/Ticket/Display.html?id=93429 .
+        - Thanks to Nick Wellnhofer for the report and test.
+
 2.0111          Wed  5 Mar 17:15:57 IST 2014
     - Skip t/40reader_mem_error.t with libxml2 < 2.7.4
       The failure is probably due to a known double-free bug.
   XML_PARSE_NOBASEFIX	  => 262144,   # do not fixup XINCLUDE xml#base uris
   XML_PARSE_HUGE	  => 524288,   # relax any hardcoded limit from the parser
   XML_PARSE_OLDSAX	  => 1048576,  # parse using SAX2 interface from before 2.7.0
+  HTML_PARSE_RECOVER => (1<<0),       # suppress error reports
+  HTML_PARSE_NOERROR  => (1<<5),       # suppress error reports
 };
 
 $XML_LIBXML_PARSE_DEFAULTS = ( XML_PARSE_NODICT | XML_PARSE_DTDLOAD | XML_PARSE_NOENT );
   $opts = {} unless ref $opts;
   #  return (undef,undef) unless ref $opts;
   my $flags = 0;
-  $flags |=     1 if exists $opts->{recover} ? $opts->{recover} : $self->recover;
+  {
+    my $recover = exists $opts->{recover} ? $opts->{recover} : $self->recover;
+
+    if ($recover)
+    {
+      $flags |= HTML_PARSE_RECOVER;
+      if ($recover == 2)
+      {
+        $flags |= HTML_PARSE_NOERROR;
+      }
+    }
+  }
+
   $flags |=     4 if $opts->{no_defdtd}; # default is ON: injects DTD as needed
   $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 :
 t/48_removeChild_crashes_rt_80395.t
 t/48_replaceNode_DTD_nodes_rT_80521.t
 t/48_rt55000.t
+t/48_rt93429_recover_2_in_html_parsing.t
 t/48importing_nodes_IDs_rt_69520.t
 t/49_load_html.t
 t/49callbacks_returning_undef.t

File t/48_rt93429_recover_2_in_html_parsing.t

+#!/usr/bin/perl
+
+# Test for:
+# https://rt.cpan.org/Ticket/Display.html?id=93429
+#
+# Contributed by Nick Wellnhofer.
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use XML::LibXML;
+
+{
+    my $err_html = '<html><body><lkj/></body></html>';
+
+    my $parser = XML::LibXML->new();
+
+    my $buf = '';
+    open(my $fh, '>', \$buf);
+
+    {
+        local *STDERR = $fh;
+        $parser->load_html( string => $err_html, recover => 2, );
+    }
+
+    close($fh);
+
+    is($buf, '', 'No warning emitted on load_html with recover => 2.');
+}
+