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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### 0.10.1
- Fixed ignore whitespace after comparison value in filter expression

### 0.10.0
- Fixed query/selector Filter Expression With Current Object
- Fixed query/selector Filter Expression With Different Grouped Operators
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/QueryMatchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QueryMatchFilter extends AbstractFilter

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

Expand Down
15 changes: 15 additions & 0 deletions tests/JSONPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ public function testQueryMatchEquals(): void
self::assertEquals('The Lord of the Rings', $result[0]);
}

/**
* $..books[?(@.category=="fiction" && @.author == \'Evelyn Waugh\')].title'
* Filter books that are in the "..." category and have an author equal to "..."
*
* @throws JSONPathException|JsonException
*/
public function testQueryMatchWhitespaceIgnored(): void
{
// Additional spaces in filter string are intended to be there
$result = (new JSONPath($this->getData('example')))
->find('$..books[?( @.category=="fiction" && @.author == \'Evelyn Waugh\' )].title');

self::assertEquals('Sword of Honour', $result[0]);
}

/**
* $..books[?(@.author = 1)]
* Filter books that have a title equal to "..."
Expand Down