Shlomi Fish avatar Shlomi Fish committed 9ddbf3e

Fix RT #77864 .

Support for references to scalars with overloaded stringification.

Thanks to CHANSEN for the report and a patch.

Comments (0)

Files changed (3)

 Revision history for Perl extension XML::LibXML
 
+    - Fix support for references to scalars with overloaded stringification
+    magic.
+        - https://rt.cpan.org/Public/Bug/Display.html?id=77864
+        - Thanks to Christian Hansen (CHANSEN) for a report, a testcase, and
+        a patch.
+
 2.0011          Thu  8 Nov 00:25:15 IST 2012
     - Fix crash in removeChild() when not expanding entities
         - https://rt.cpan.org/Ticket/Display.html?id=80395
     PREINIT:
         char * directory = NULL;
         STRLEN len;
-        char * ptr;
+        const char * ptr;
         HV * real_obj;
         int well_formed;
         int valid;
             }
         }
         /* If string is a reference to a string - dereference it.
-         * See: https://rt.cpan.org/Ticket/Display.html?id=64051 . */
-        if (SvROK(string)) {
+         * 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);
+        ptr = SvPV_const(string, len);
         if (len <= 0) {
             croak("Empty string\n");
             XSRETURN_UNDEF;
         RETVAL = &PL_sv_undef;
         INIT_ERROR_HANDLER;
         {
-            xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
+            xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(ptr, len);
             if (ctxt == NULL) {
 	        CLEANUP_ERROR_HANDLER;
                 REPORT_ERROR(1);
 use warnings;
 
 # Should be 168.
-use Test::More tests => 180;
+use Test::More tests => 193;
 
 use XML::LibXML;
 use XML::LibXML::Common qw(:libxml);
     }
 }
 
+package Stringify;
+
+use overload q[""] => sub { return '<A xmlns:C="xml://D"><C:A>foo<A/>bar</C:A><A><C:B/>X</A>baz</A>'; };
+
+sub new
+{
+    return bless \(my $x);
+}
+
+package main;
+
 {
     # Document Storing
     my $parser = XML::LibXML->new;
 =end taken_out
 
 =cut
-    # TEST:$count=2;
+    # TEST:$count=3;
     # Also test that we can parse from scalar references:
     # See RT #64051 ( https://rt.cpan.org/Ticket/Display.html?id=64051 )
-        foreach my $input ( $string5, \$string5 )
+    # Also test that we can parse from references to scalars with
+    # overloaded strings:
+    # See RT #77864 ( https://rt.cpan.org/Public/Bug/Display.html?id=77864 )
+
+        my $obj = Stringify->new;
+
+        foreach my $input ( $string5, (\$string5), $obj )
         {
             my $doc2 = $parser2->parse_string($input);
             # TEST*$count
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.