fix(filter): allow bare @ adjacent to an operator without whitespace#267
Open
spokodev wants to merge 1 commit into
Open
fix(filter): allow bare @ adjacent to an operator without whitespace#267spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
The current-node token @ was only substituted for _$_v when followed by '.', whitespace, ')' or '['. A bare @ directly before a comparison or arithmetic operator (e.g. $[?(@>1)] or $[?(@===2)]) was left untouched, so the compiled filter script started with a literal @ and failed to parse under both the safe and native evaluators. Extend the delimiter set with the operator characters so these expressions evaluate; @ inside identifiers and quoted keys (e.g. @['@tag']) stays protected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
A filter with a bare
@(the current node) placed directly against an operator, with no whitespace, fails to evaluate:The same query works only if a space is added:
$[?(@ > 1)].Cause
In
_eval, the current-node token@is rewritten to the sandbox variable_$_vby:The character class only allows
@to be followed by., whitespace,)or[. When@is immediately followed by a comparison or arithmetic operator (>,<,==,!=,%,+,-,*,/,&,|), it is left as a literal@, so the compiled filter script begins with@and neither the safe (jsep) nor the native (vm) evaluator can parse it.Fix
Add those operator characters to the delimiter class:
@inside identifiers and quoted keys is still protected (it is only rewritten when followed by an operator/delimiter, never a word character), so cases like@['@tag']are unaffected.Adds a regression test covering
@>,@<,@===and@!==with no surrounding whitespace. Full suite passes and lint is clean.