Skip to content

Commit d8ed226

Browse files
committed
Fixes #20
1 parent d6ad6bc commit d8ed226

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Filters/QueryMatchFilter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Flow\JSONPath\Filters;
1010

1111
use Flow\JSONPath\AccessHelper;
12+
use Flow\JSONPath\JSONPath;
1213
use RuntimeException;
1314

1415
class QueryMatchFilter extends AbstractFilter
@@ -20,7 +21,7 @@ class QueryMatchFilter extends AbstractFilter
2021

2122
public function filter($collection): array
2223
{
23-
\preg_match('/^' . static::MATCH_QUERY_OPERATORS . '$/x', $this->token->value, $matches);
24+
\preg_match('/^'.static::MATCH_QUERY_OPERATORS.'$/x', $this->token->value, $matches);
2425

2526
if (!isset($matches[1])) {
2627
throw new RuntimeException('Malformed filter query');
@@ -59,9 +60,13 @@ public function filter($collection): array
5960
$return = [];
6061

6162
foreach ($collection as $value) {
63+
$value1 = null;
6264
if (AccessHelper::keyExists($value, $key, $this->magicIsAllowed)) {
6365
$value1 = AccessHelper::getValue($value, $key, $this->magicIsAllowed);
64-
66+
} elseif (str_contains($key, '.')) {
67+
$value1 = (new JSONPath($value))->find($key)->getData()[0];
68+
}
69+
if ($value1) {
6570
if ($operator === null && $value1) {
6671
$return[] = $value;
6772
}

tests/data/baselineFailedQueries.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ filter_expression_with_greater_than_or_equal
2626
filter_expression_with_less_than
2727
filter_expression_with_less_than_or_equal
2828
filter_expression_with_not_equals
29-
filter_expression_with_subpaths
3029
filter_expression_with_value
3130
script_expression
3231
union_with_filter

0 commit comments

Comments
 (0)