Commits

Shlomi Fish committed db5c1ec

Fix RT #87089 - HTML DOCTYPE should be retained.

  • Participants
  • Parent commits d3953bf

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
+2.0101          Thu 15 Aug 08:29:15 IDT 2013
+    - Fixed https://rt.cpan.org/Ticket/Display.html?id=87089 .
+        - "HTML doctype differs for string/scalar input"
+        - Thanks to NGLENN for the report and to Yuriy for the tests and
+        fix.
+
 2.0100          Wed 14 Aug 08:23:53 IDT 2013
     - Added the unique_key() method to XML::LibXML::Node.
     - t/40reader.t: assigning from $@ to a lexical so it won't be
         int recover = 0;
         PREINIT_SAVED_ERROR
     INIT:
+        /* If string is a reference to a string - dereference it.
+         * See: https://rt.cpan.org/Ticket/Display.html?id=64051 (broke it)
+         *      https://rt.cpan.org/Ticket/Display.html?id=77864 (fixed it) */
+        if (SvROK(string) && !SvOBJECT(SvRV(string))) {
+            string = SvRV(string);
+        }
         ptr = SvPV(string, len);
         if (len <= 0) {
             croak("Empty string\n");
 t/49callbacks_returning_undef.t
 t/49global_extent.t
 t/50devel.t
+t/51_parse_html_string_rt87089.t
 t/60error_prev_chain.t
 t/60struct_error.t
 t/61error.t

File t/51_parse_html_string_rt87089.t

+
+use strict;
+use warnings;
+
+=head1 DESCRIPTION
+
+Getting wrong result when parsing HTML string as a scalar reference.
+
+See L<https://rt.cpan.org/Ticket/Display.html?id=87089> .
+
+=cut
+
+use Test::More tests => 2;
+
+use XML::LibXML;
+
+my $parser = XML::LibXML->new();
+
+# Parse HTML string as scalar
+{
+    my $dom = $parser->load_html(string => '<!DOCTYPE html><html>');
+    # TEST
+    is ($dom->toStringHTML, "<!DOCTYPE html>\n<html></html>\n",
+        "Parse HTML string as scalar");
+}
+
+# Parse HTML string as scalar reference
+{
+    my $dom = $parser->load_html(string => \'<!DOCTYPE html><html>');
+    # TEST
+    is ($dom->toStringHTML, "<!DOCTYPE html>\n<html></html>\n",
+        "Parse HTML string as scalar reference");
+}