Skip to content

Commit

Permalink
Merge pull request #18 from Madskill/fix_unescape
Browse files Browse the repository at this point in the history
fix unescape
  • Loading branch information
renormalist authored Aug 28, 2019
2 parents d40e8f4 + 726ff7d commit 15717f1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Data/DPath/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ sub unescape {
my ($str) = @_;

return unless defined $str;
$str =~ s/(?<!\\)\\(["'])/$1/g; # '"$
$str =~ s/\\{2}/\\/g;
$str =~ s/\\(["'])/$1/g; # '"$
return $str;
}

Expand Down
41 changes: 41 additions & 0 deletions t/data_dpath_path_unescape.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env perl

use strict;
use warnings FATAL => 'all';
use utf8;

use Test::More tests => 6;

use_ok('Data::DPath::Path');

my $FIXTURES = [
{
name => 'double quote',
string => '\\"',
result => '"',
},
{
name => 'backslash',
string => '\\\\',
result => '\\',
},
{
name => 'backslash with double quote',
string => '\\\\\\"',
result => '\\"',
},
{
name => 'two backslash with double quote',
string => '\\\\\\\\\\"',
result => '\\\\"',
},
{
name => 'example from documentations',
string => '\"EE\E5\\\\\\"',
result => '"EE\E5\"',
},
];

foreach my $test (@$FIXTURES) {
is(Data::DPath::Path::unescape($test->{'string'}), $test->{'result'}, $test->{'name'});
}
4 changes: 2 additions & 2 deletions t/path.t
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ is_deeply(\@parts, [
'"EE E2"',
'"EE E3"[1]',
'"EE E4"',
'"EE\E5\\\\"',
'"EE\E5\\"',
'"FFF"',
'GGG[foo == bar]',
'*',
Expand Down Expand Up @@ -181,7 +181,7 @@ is_deeply(\@parts, [
'"EE E2"',
'"EE E3"[1]',
'"EE E4"',
'"EE\E5\\\\"',
'"EE\E5\\"',
'"FFF"',
'GGG[foo == bar]',
'*',
Expand Down

0 comments on commit 15717f1

Please sign in to comment.