Fix JSONPath syntax error with in filter after other filters#4001
Open
caglareker wants to merge 2 commits intoalibaba:mainfrom
Open
Fix JSONPath syntax error with in filter after other filters#4001caglareker wants to merge 2 commits intoalibaba:mainfrom
caglareker wants to merge 2 commits intoalibaba:mainfrom
Conversation
When parsing filter expressions, the parser was unconditionally requiring a closing parenthesis even when the filter wasn't wrapped in parentheses. This caused errors when an 'in' filter followed other filter conditions, since the 'in' filter has its own parenthetical syntax. Only enforce the closing parenthesis requirement when the filter itself is wrapped in parentheses.
|
|
jujn
reviewed
Feb 28, 2026
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class JSONPath_in_filter_issue3997 { |
Collaborator
There was a problem hiding this comment.
Could you please move this unit test to the test/java/com/alibaba/fastjson2/issues_3900 directory and rename the class to Issue3997? Thanks
Collaborator
There was a problem hiding this comment.
OK. Let's wait for @wenshao to review this, as he handles all write operations.
Member
|
This PR fails the unit test; please try merging from the main branch. |
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.
Summary
Fix a parser error that occurred when using an 'in' filter in combination with other filters in JSONPath expressions. The parser was unconditionally requiring a closing parenthesis after parsing filters, which caused syntax errors when the 'in' filter's own parentheses were present.
Changes
Modify the filter parsing logic in
JSONPathParserto only enforce the closing parenthesis requirement when the filter expression itself is wrapped in parentheses. This allows 'in' filters with their own parenthetical syntax to work correctly after other filter conditions.Testing
Add test cases validating:
@.field=='value' && @.type in ('01','04'))Both scenarios now parse and evaluate correctly.
Fixes #3997