-
-
Notifications
You must be signed in to change notification settings - Fork 835
Fix parsing of keys containing literal [] inside bracket groups
#530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
[] inside bracket groups
|
@ljharb, it seems some of the tests fail because the runners are unable to download a specific Node version, i.e. |
|
@ljharb, have you had a chance to look at this yet? 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements bracket balancing in the query string parser to correctly handle literal [] characters inside bracket groups. Previously, bracket pairs within a bracket group could cause parsing issues. The new implementation uses a level counter to properly balance opening and closing brackets, treating inner bracket pairs as literal parts of keys.
Key Changes
- Refactored
parseKeysfunction to extract bracket parsing logic into a newsplitKeyIntoSegmentshelper function - Implemented bracket-balancing algorithm that uses a level counter to track nested brackets
- Added test cases validating that
[]inside bracket groups are treated as literal key characters
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/parse.js | Replaced regex-based bracket parsing with bracket-balancing algorithm that correctly handles nested [] within bracket groups |
| test/parse.js | Added test case covering three scenarios: basic nested brackets, single-level variant, and array push with nested brackets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty hard to review. Could you perhaps make a refactoring commit that makes the majority of the changes, and then a fix commit with the test and the thing that makes the test pass?
243b1f5 to
bb1b7c3
Compare
@ljharb done. 😇 I have split the parse key processing into a refactor-only commit followed by the nested-bracket fix plus its regression tests so it now has the structure you have asked for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Problem
qssplits bracket groups with a regex that forbids[]inside a group:This causes keys like
search[withbracket[]]to split into"[withbracket]", then"[]", leaving the inner[]detached from the literal segment. Downstream, it can no longer be treated as a single literal key.Repro
Fix approach
Backport
splitKeyIntoSegmentsfrom qs_dart and replace the regex child matcher with a balanced bracket splitter that treats[]inside a bracket group as literal content (only outer[]act as array push). This preserveswithbracket[]as a single segment.Notes
[]at the outermost level (array push).allowDots,depth,strictDepth,allowPrototypes, etc.Test snippet
Fixes #493