Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filters #22

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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 @@ -95,7 +95,7 @@ sub _build__steps {
# - 2) use the part before "["
# - 3) unshift the rest to remaining
# - 4) extract_codeblock() explicitely
if ($extracted =~ /(.*)((?<!\\)\[.*)/ and $extracted !~ m|\]/\s*$|) {
if ($extracted =~ /(.*?)(\[.*)/ and $extracted !~ m|\]/\s*$|) {
$remaining_path = $2 . $remaining_path;
( $plain_part = $1 ) =~ s|^/||;
($filter, $remaining_path) = extract_codeblock($remaining_path, "[]");
Expand Down
45 changes: 45 additions & 0 deletions t/filters_with_special_symbols.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#! /usr/bin/env perl

use strict;
use warnings;

use Test::More 0.88 tests => 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 = [
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.
#
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 $path (@$FIXTURES) {
my @result = dpath($path)->match($data);

ok(@result == 1);
is($result[0], $value, $path);
}