Commits

Shlomi Fish  committed a620e3b

Convert to quotemeta - fixing RT # 68564.

- In replaceDataString - use
http://perldoc.perl.org/functions/quotemeta.html instead of a long (and
incomplete) list of characters to escape.
-- With test.
-- Fixing https://rt.cpan.org/Ticket/Display.html?id=68564
-- Thanks to Daniel Perrett .

  • Participants
  • Parent commits 85971aa

Comments (0)

Files changed (3)

       from https://rt.cpan.org/Public/Bug/Display.html?id=68575
         -- Applied by SHLOMIF.
         -- Thanks to Aaron Crane.
+    - In replaceDataString - use 
+    http://perldoc.perl.org/functions/quotemeta.html instead of a long (and
+    incomplete) list of characters to escape.
+        -- With test.
+        -- Fixing https://rt.cpan.org/Ticket/Display.html?id=68564
+        -- Thanks to Daniel Perrett .
+
 
 1.70
    - various fixes and improvements in the documentation
 }
 
 sub replaceDataString {
-    my ( $node, $left, $right,$all ) = @_;
+    my ( $node, $left_proto, $right,$all ) = @_;
 
-    #ashure we exchange the strings and not expressions!
-    $left  =~ s/([\\\*\+\^\{\}\&\?\[\]\(\)\$\%\@])/\\$1/g;
+    # Assure we exchange the strings and not expressions!
+    my $left = quotemeta($left_proto);
+
     my $datastr = $node->nodeValue();
     if ( $all ) {
         $datastr =~ s/$left/$right/g;
 
 use Test;
 
-BEGIN { plan tests => 32 };
+BEGIN { plan tests => 33 };
 use XML::LibXML;
 
 my $doc = XML::LibXML::Document->new();
     $textnode->replaceDataString( "e?s", 'ne\w' );   
     ok( $textnode->nodeValue(), 'tne\wt' );
 
+    # check if "." is encoded properly 
+    $textnode->setData( "h.thrt");
+    $textnode->replaceDataString( "h.t", 'new', 1 );   
+    ok( $textnode->nodeValue(), 'newhrt' );
+
     # check if entities don't get translated
     $textnode->setData(q(foo&bar));
     ok ( $textnode->getData eq q(foo&bar) );
     my $node = XML::LibXML::DocumentFragment->new();
 
     ok( $node->nodeName(), "#document-fragment" );
-}
+}