Commits

Shlomi Fish committed 3ee145c

Fix deleteDataString.

Comments (0)

Files changed (3)

     http://perldoc.perl.org/functions/quotemeta.html instead of a long (and
     incomplete) list of characters to escape.
         -- With test.
+        -- also fix deleteDataString by making it use replaceDataString
+        for help.
         -- Fixing https://rt.cpan.org/Ticket/Display.html?id=68564
         -- Thanks to Daniel Perrett .
 
 sub attributes { return undef; }
 
 sub deleteDataString {
-    my $node = shift;
-    my $string = shift;
-    my $all    = shift;
-    my $data = $node->nodeValue();
-    $string =~ s/([\\\*\+\^\{\}\&\?\[\]\(\)\$\%\@])/\\$1/g;
-    if ( $all ) {
-        $data =~ s/$string//g;
-    }
-    else {
-        $data =~ s/$string//;
-    }
-    $node->setData( $data );
+    my ($node, $string, $all) = @_;
+
+    return $node->replaceDataString($string, '', $all);
 }
 
 sub replaceDataString {
 
 use Test;
 
-BEGIN { plan tests => 33 };
+BEGIN { plan tests => 36 };
 use XML::LibXML;
 
 my $doc = XML::LibXML::Document->new();
     $textnode->replaceDataString( "h.t", 'new', 1 );   
     ok( $textnode->nodeValue(), 'newhrt' );
 
+    # check if deleteDataString does not delete dots.
+    $textnode->setData( 'hitpit' );
+    $textnode->deleteDataString( 'h.t' );   
+    ok( $textnode->nodeValue(), 'hitpit' );
+
+    # check if deleteDataString works
+    $textnode->setData( 'hitpithit' );
+    $textnode->deleteDataString( 'hit' );   
+    ok( $textnode->nodeValue(), 'pithit' );
+
+    # check if deleteDataString all works
+    $textnode->setData( 'hitpithit' );
+    $textnode->deleteDataString( 'hit', 1 );   
+    ok( $textnode->nodeValue(), 'pit' );
+
     # check if entities don't get translated
     $textnode->setData(q(foo&bar));
     ok ( $textnode->getData eq q(foo&bar) );