Commits

Nick Wellnhofer committed 5262469

Fix substringData method on text nodes

The length argument passed to xmlStrsub was bogus. Furthermore,
xmlUTF8Strsub should be used.

Fixes RT #88730
https://rt.cpan.org/Ticket/Display.html?id=88730

  • Participants
  • Parent commits 3a73b7c

Comments (0)

Files changed (3)

 Revision history for Perl extension XML::LibXML
 
+Not yet released
+    - Fix substringData
+        - https://rt.cpan.org/Ticket/Display.html?id=88730
+
 2.0110          Sat  1 Feb 15:59:54 IST 2014
     - Add "use strict;" and "use warnings;" to all modules (CPANTS).
     - MIN_PERL_VERSION (CPANTS).
     PREINIT:
         xmlChar * data = NULL;
         xmlChar * substr = NULL;
-        int len = 0;
-        int dl = 0;
-    CODE:
-        if ( offset >= 0 && length > 0 ) {
-            dl = offset + length - 1 ;
+    CODE:
+        if ( offset >= 0 && length >= 0 ) {
             data = domGetNodeValue( self );
-            len = xmlStrlen( data );
-            if ( data != NULL && len > 0 && len > offset ) {
-                if ( dl > len )
-                    dl = offset + len;
-
-                substr = xmlStrsub( data, offset, dl );
+            if ( data != NULL ) {
+                substr = xmlUTF8Strsub( data, offset, length );
                 RETVAL = C2Sv( (const xmlChar*)substr, NULL );
                 xmlFree( substr );
             }
 use strict;
 use warnings;
 
-use Test::More tests => 36;
+use Test::More tests => 37;
 
 use XML::LibXML;
 
     my $tnstr = $textnode->substringData( 1,2 );
     # TEST
     is( $tnstr , "oo", 'substring 1');
+    $tnstr = $textnode->substringData( 0,3 );
     # TEST
-    is( $textnode->nodeValue(), $foo,  'substring 2' );
+    is( $tnstr , "foo", 'substring 2');
+    # TEST
+    is( $textnode->nodeValue(), $foo,  'substring - text node unchanged' );
 
     # 3. Expansion
     $textnode->appendData( $foo );