Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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