fix: nested query keys containing literal bracket pairs#6
Open
codefix-patchflow[bot] wants to merge 1 commit into
Conversation
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.
What failed
Parsing a query key like:
search[withbracket[]]=foobartreated the inner
[]as the only recognizable bracket segment. That made the parser split the parent key incorrectly and return:{ "search[withbracket": ["foobar"] }The intended behavior is to keep
withbracket[]as the nested property name undersearch.What changed
Replaced the regex-only bracket segment matcher in
lib/parse.jswith a small scanner that finds balanced bracket segments The scanner preserves normal nested syntax such asa[b][c], while allowing bracket pairs inside a segment, such assearch[withbracket[]], to remain part of that segment's key nameWhy this works
The previous regex could only match bracket groups that contained no
[or], so it skipped the outersearch[...]segment and matched the inner[]instead The new scanner counts nested brackets until the outer segment closes. This produces the segment[withbracket[]], which the existing object builder already converts into the literal keywithbracket[]Prototype-key checks and depth-limit remainder handling still run through the samesplitKeyIntoSegmentspathExpected result
qs.parse('search[withbracket[]]=foobar')should now produce a nestedsearchobject with the property namewithbracket[], matching the stringify/parse round trip from the failure report Existing array notation and depth-limit behavior should remain unchangedPatchflow did not run repository-local commands; the automated review gate checks the patch without assuming the project full runtime environment is available.
🔧 Fixed automatically by Patchflow — $1/fix · no fix, no fee
Automation details