Skip to content

Commit b74ad33

Browse files
committed
Fixed: ignore whitespace after comparator in filter expression
1 parent 74f0b33 commit b74ad33

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### 0.10.1
4+
- Fixed ignore whitespace after comparison value in filter expression
5+
36
### 0.10.0
47
- Fixed query/selector Filter Expression With Current Object
58
- Fixed query/selector Filter Expression With Different Grouped Operators

src/Filters/QueryMatchFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class QueryMatchFilter extends AbstractFilter
2828

2929
protected const MATCH_QUERY_OPERATORS = '
3030
(@\.(?<key>[^\s<>!=]+)|@\[["\']?(?<keySquare>.*?)["\']?\]|(?<node>@)|(%group(?<group>\d+)%))
31-
(\s*(?<operator>==|=~|=|<>|!==|!=|>=|<=|>|<|in|!in|nin)\s*(?<comparisonValue>.+?(?=(&&|$|\|\||%))))?
31+
(\s*(?<operator>==|=~|=|<>|!==|!=|>=|<=|>|<|in|!in|nin)\s*(?<comparisonValue>.+?(?=\s*(?:&&|$|\|\||%))))?
3232
(\s*(?<logicalandor>&&|\|\|)\s*)?
3333
';
3434

tests/JSONPathTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ public function testQueryMatchEquals(): void
324324
self::assertEquals('The Lord of the Rings', $result[0]);
325325
}
326326

327+
/**
328+
* $..books[?(@.category=="fiction" && @.author == \'Evelyn Waugh\')].title'
329+
* Filter books that are in the "..." category and have an author equal to "..."
330+
*
331+
* @throws JSONPathException|JsonException
332+
*/
333+
public function testQueryMatchWhitespaceIgnored(): void
334+
{
335+
// Additional spaces in filter string are intended to be there
336+
$result = (new JSONPath($this->getData('example')))
337+
->find('$..books[?( @.category=="fiction" && @.author == \'Evelyn Waugh\' )].title');
338+
339+
self::assertEquals('Sword of Honour', $result[0]);
340+
}
341+
327342
/**
328343
* $..books[?(@.author = 1)]
329344
* Filter books that have a title equal to "..."

0 commit comments

Comments
 (0)