Fix parsing of keys containing literal [] inside bracket groups#530
Fix parsing of keys containing literal [] inside bracket groups#530techouse wants to merge 1 commit intoljharb:mainfrom
[] inside bracket groups#530Conversation
[] 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.
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.
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.
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.
|
Thanks for the review, @ljharb 😇 I have pushed updates to align with
I have also added regression coverage for depth-0 behavior ( The merge conflicts were quite the challenge (this PR is from August!), so I hope I didn't mess up somewhere 😅 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
98bc892 to
172525a
Compare
There was a problem hiding this comment.
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.
9eb32ca to
bc25549
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 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