From c8b16b0a91ac15a5adaf935c2cdd483a7ca43a13 Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Mon, 15 Oct 2018 01:14:21 +0300 Subject: [PATCH 1/7] fix unescape --- lib/Data/DPath/Path.pm | 2 +- t/data_dpath_path_unescape.t | 41 ++++++++++++++++++++++++++++++++++++ t/path.t | 4 ++-- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 t/data_dpath_path_unescape.t diff --git a/lib/Data/DPath/Path.pm b/lib/Data/DPath/Path.pm index 10abac6..ab25fa1 100644 --- a/lib/Data/DPath/Path.pm +++ b/lib/Data/DPath/Path.pm @@ -39,8 +39,8 @@ sub unescape { my ($str) = @_; return unless defined $str; - $str =~ s/(? 'all'; +use utf8; + +use Test::More tests => 6; + +use_ok('Data::DPath::Path'); + +my $FIXTURE = [ + { + 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 (@$FIXTURE) { + is(Data::DPath::Path::unescape($test->{'string'}), $test->{'result'}, $test->{'name'}); +} diff --git a/t/path.t b/t/path.t index d8e0127..8956d16 100644 --- a/t/path.t +++ b/t/path.t @@ -86,7 +86,7 @@ is_deeply(\@parts, [ '"EE E2"', '"EE E3"[1]', '"EE E4"', - '"EE\E5\\\\"', + '"EE\E5\\"', '"FFF"', 'GGG[foo == bar]', '*', @@ -181,7 +181,7 @@ is_deeply(\@parts, [ '"EE E2"', '"EE E3"[1]', '"EE E4"', - '"EE\E5\\\\"', + '"EE\E5\\"', '"FFF"', 'GGG[foo == bar]', '*', From 7a1316035b587edcadb8227bfbfaf12b0608b698 Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Sun, 21 Oct 2018 19:49:25 +0300 Subject: [PATCH 2/7] rename: $FIXTURE -> $FIXTURES --- t/data_dpath_path_unescape.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/data_dpath_path_unescape.t b/t/data_dpath_path_unescape.t index d9e2c7c..0c38100 100644 --- a/t/data_dpath_path_unescape.t +++ b/t/data_dpath_path_unescape.t @@ -8,7 +8,7 @@ use Test::More tests => 6; use_ok('Data::DPath::Path'); -my $FIXTURE = [ +my $FIXTURES = [ { name => 'double quote', string => '\\"', @@ -36,6 +36,6 @@ my $FIXTURE = [ }, ]; -foreach my $test (@$FIXTURE) { +foreach my $test (@$FIXTURES) { is(Data::DPath::Path::unescape($test->{'string'}), $test->{'result'}, $test->{'name'}); } From 09b65d71eb55cc7cd7f0ad100e61573d753eea6d Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Sat, 24 Nov 2018 23:38:29 +0300 Subject: [PATCH 3/7] fix filters --- lib/Data/DPath/Path.pm | 2 +- t/filters_with_special_symbols.t | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 t/filters_with_special_symbols.t diff --git a/lib/Data/DPath/Path.pm b/lib/Data/DPath/Path.pm index ab25fa1..c4ec154 100644 --- a/lib/Data/DPath/Path.pm +++ b/lib/Data/DPath/Path.pm @@ -95,7 +95,7 @@ sub _build__steps { # - 2) use the part before "[" # - 3) unshift the rest to remaining # - 4) extract_codeblock() explicitely - if ($extracted =~ /(.*)((? 28; +use Data::DPath 'dpath'; + +my @fields = ( + 'simpleFild', 'fieldWithBackSlash\\', + '\'fieldWithQoute\'', ']fieldWithSquareBrackets[', + '[fieldWithSquareBrackets]', '"fieldWithDoubleQoute"', + 'fieldWithSlash/', +); + +my $value = 'aaa[bbb/ccc]ddd"eee\'fff'; + +my $data = {map {$_ => $value} @fields}; + +my $FIXTURES = [ + { + path => q!/simpleFild[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/simpleFild[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, + { + path => q!/fieldWithBackSlash\\[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/fieldWithBackSlash\\[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, + { + path => q!/'fieldWithQoute'[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/'fieldWithQoute'[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, + # + # If the key contains square brackets, slash or double quotes, it must be enclosed in double quotes. + # + { + path => q!/"]fieldWithSquareBrackets["[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/"]fieldWithSquareBrackets["[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, + { + path => q!/"[fieldWithSquareBrackets]"[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/"[fieldWithSquareBrackets]"[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, + { + path => q!/"\"fieldWithDoubleQoute\""[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/"\"fieldWithDoubleQoute\""[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, + { + path => q!/"fieldWithSlash/"[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + result => $value, + }, + { + path => q!/"fieldWithSlash/"[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + result => $value, + }, +]; + +foreach my $test (@$FIXTURES) { + my @result = dpath($test->{'path'})->match($data); + + ok(@result == 1); + is($result[0], $test->{'result'}, $test->{'path'}); +} From 4e44ffeee21ad8d3dedb11e8297e3320752db8dc Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Sat, 24 Nov 2018 23:42:51 +0300 Subject: [PATCH 4/7] Revert "rename: $FIXTURE -> $FIXTURES" This reverts commit 726ff7d9576499af67f1128f4d13f0f5d6527c97. --- t/data_dpath_path_unescape.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/data_dpath_path_unescape.t b/t/data_dpath_path_unescape.t index 0c38100..d9e2c7c 100644 --- a/t/data_dpath_path_unescape.t +++ b/t/data_dpath_path_unescape.t @@ -8,7 +8,7 @@ use Test::More tests => 6; use_ok('Data::DPath::Path'); -my $FIXTURES = [ +my $FIXTURE = [ { name => 'double quote', string => '\\"', @@ -36,6 +36,6 @@ my $FIXTURES = [ }, ]; -foreach my $test (@$FIXTURES) { +foreach my $test (@$FIXTURE) { is(Data::DPath::Path::unescape($test->{'string'}), $test->{'result'}, $test->{'name'}); } From 9b0ba2fcfdd51863d33ceb4dbe495d57478d04f9 Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Sat, 24 Nov 2018 23:43:04 +0300 Subject: [PATCH 5/7] Revert "fix unescape" This reverts commit 8f92e4ba49ee5767976b16936630d908af47f9b4. --- lib/Data/DPath/Path.pm | 2 +- t/data_dpath_path_unescape.t | 41 ------------------------------------ t/path.t | 4 ++-- 3 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 t/data_dpath_path_unescape.t diff --git a/lib/Data/DPath/Path.pm b/lib/Data/DPath/Path.pm index c4ec154..3177c17 100644 --- a/lib/Data/DPath/Path.pm +++ b/lib/Data/DPath/Path.pm @@ -39,8 +39,8 @@ sub unescape { my ($str) = @_; return unless defined $str; + $str =~ s/(? 'all'; -use utf8; - -use Test::More tests => 6; - -use_ok('Data::DPath::Path'); - -my $FIXTURE = [ - { - 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 (@$FIXTURE) { - is(Data::DPath::Path::unescape($test->{'string'}), $test->{'result'}, $test->{'name'}); -} diff --git a/t/path.t b/t/path.t index 8956d16..d8e0127 100644 --- a/t/path.t +++ b/t/path.t @@ -86,7 +86,7 @@ is_deeply(\@parts, [ '"EE E2"', '"EE E3"[1]', '"EE E4"', - '"EE\E5\\"', + '"EE\E5\\\\"', '"FFF"', 'GGG[foo == bar]', '*', @@ -181,7 +181,7 @@ is_deeply(\@parts, [ '"EE E2"', '"EE E3"[1]', '"EE E4"', - '"EE\E5\\"', + '"EE\E5\\\\"', '"FFF"', 'GGG[foo == bar]', '*', From 841cab87e474e69e9a80241203ef72b2f8a32ddd Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Sun, 25 Nov 2018 00:02:09 +0300 Subject: [PATCH 6/7] fix path with backslash --- lib/Data/DPath/Path.pm | 2 +- t/filters_with_special_symbols.t | 76 +++++++------------------------- 2 files changed, 18 insertions(+), 60 deletions(-) diff --git a/lib/Data/DPath/Path.pm b/lib/Data/DPath/Path.pm index 3177c17..066e457 100644 --- a/lib/Data/DPath/Path.pm +++ b/lib/Data/DPath/Path.pm @@ -95,7 +95,7 @@ sub _build__steps { # - 2) use the part before "[" # - 3) unshift the rest to remaining # - 4) extract_codeblock() explicitely - if ($extracted =~ /(.*?)((? $value} @fields}; my $FIXTURES = [ - { - path => q!/simpleFild[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/simpleFild[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, - { - path => q!/fieldWithBackSlash\\[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/fieldWithBackSlash\\[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, - { - path => q!/'fieldWithQoute'[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/'fieldWithQoute'[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, + q!/simpleFild[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/simpleFild[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + q!/fieldWithBackSlash\\\\[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/fieldWithBackSlash\\\\[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + q!/'fieldWithQoute'[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/'fieldWithQoute'[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, # # If the key contains square brackets, slash or double quotes, it must be enclosed in double quotes. # - { - path => q!/"]fieldWithSquareBrackets["[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/"]fieldWithSquareBrackets["[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, - { - path => q!/"[fieldWithSquareBrackets]"[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/"[fieldWithSquareBrackets]"[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, - { - path => q!/"\"fieldWithDoubleQoute\""[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/"\"fieldWithDoubleQoute\""[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, - { - path => q!/"fieldWithSlash/"[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - result => $value, - }, - { - path => q!/"fieldWithSlash/"[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - result => $value, - }, + q!/"]fieldWithSquareBrackets["[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/"]fieldWithSquareBrackets["[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + q!/"[fieldWithSquareBrackets]"[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/"[fieldWithSquareBrackets]"[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + q!/"\"fieldWithDoubleQoute\""[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/"\"fieldWithDoubleQoute\""[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + q!/"fieldWithSlash/"[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/"fieldWithSlash/"[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, ]; -foreach my $test (@$FIXTURES) { - my @result = dpath($test->{'path'})->match($data); +foreach my $path (@$FIXTURES) { + my @result = dpath($path)->match($data); ok(@result == 1); - is($result[0], $test->{'result'}, $test->{'path'}); + is($result[0], $value, $path); } From 412c6b43b9cb88858fd2db5ff9f97747cd8f995e Mon Sep 17 00:00:00 2001 From: Igor Sverdlov Date: Sun, 25 Nov 2018 06:04:45 +0300 Subject: [PATCH 7/7] use double backslash --- t/filters_with_special_symbols.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/filters_with_special_symbols.t b/t/filters_with_special_symbols.t index 1336f7d..1e5788c 100644 --- a/t/filters_with_special_symbols.t +++ b/t/filters_with_special_symbols.t @@ -20,8 +20,8 @@ my $data = {map {$_ => $value} @fields}; my $FIXTURES = [ q!/simpleFild[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, q!/simpleFild[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, - q!/fieldWithBackSlash\\\\[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, - q!/fieldWithBackSlash\\\\[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, + q!/fieldWithBackSlash\\[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, + q!/fieldWithBackSlash\\[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, q!/'fieldWithQoute'[value eq 'aaa[bbb/ccc]ddd"eee\'fff']!, q!/'fieldWithQoute'[value eq "aaa[bbb/ccc]ddd\"eee'fff"]!, #