Skip to content

fix: handle require edge case#2

Open
codefix-patchflow[bot] wants to merge 1 commit into
patchflow-red-qs-493from
codefix/1a288cfd-search-parameters-with-closing-square-bracket-in
Open

fix: handle require edge case#2
codefix-patchflow[bot] wants to merge 1 commit into
patchflow-red-qs-493from
codefix/1a288cfd-search-parameters-with-closing-square-bracket-in

Conversation

@codefix-patchflow

Copy link
Copy Markdown

What failed

Search parameters with closing square bracket in nested property names are parsed incorrectly.

Here demonstrated with /?search[withbracket[]]=foobar:

var qs = require("qs");
undefined
input = { search: { "withbracket[]": "foobar" }}
{ search: { 'withbracket[]': 'foobar' } }
output = qs.stringify(input, { encode: false })
'search[withbracket[]]=foobar'
result = qs.parse(output)
{ 'search[withbracket': [ 'foobar' ] }
assert.deepEqual(input, result)
Uncaught AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:

{
search: {
'withbracket[]': 'foobar'
}
}

should loosely deep-equal

{
'search[withbracket': [
'foobar'
]
}
at REPL280:1:8
at Script.runInThisContext (node:vm:129:12)
at REPLServer.defaultEval (node:repl:572:29)
at bound (node:domain:433:15)
at REPLServer.runBound [as eval] (node:domain:444:12)
at REPLServer.onLine (node:repl:902:10)
at REPLServer.emit (node:events:525:35)
at REPLServer.emit (node:domain:489:12)
at [_onLine] [as _onLine] (node:internal/readline/interface:425:12)
at [_line] [as _line] (node:internal/readline/interface:886:18) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: [Object],
expected: [Object],
operator: 'deepEqual'
}
For comparison the result with the native URL object:

url = new URL("http://example.com/?search[withbracket[]]=foobar")
URL {
href: 'http://example.com/?search[withbracket[]]=foobar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '?search[withbracket[]]=foobar',
searchParams: URLSearchParams { 'search[withbracket[]]' => 'foobar' },
hash: ''
}
[...url.searchParams.keys()]
[ 'search[withbracket[]]' ]
When parsing a query without braces, the result looks like:

qs.parse("search[okay]=baz")
{ search: { okay: 'baz' } }
So it should be a nested object.

Current Result
{ "search[withbracket": ["foobar"] }
Expected Result
{ "search": { "withbracket[]": ["foobar"] }}

What changed

Patchflow applied a minimal source change for the reported failure.

  • lib/parse.js around line 227 (modified, +35/-6)

Why this works

The patch is scoped to the failing path and preserves existing behavior outside the touched code.

Expected result

A concise pull request is created with a clear review note

Patchflow 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
  • Job ID: 1a288cfd-91ce-46cc-8d33-20d1db9fef10
  • Repository: CDEN190/qs
  • Branch: codefix/1a288cfd-search-parameters-with-closing-square-bracket-in
  • Base branch: patchflow-red-qs-493
  • Reference command: None
  • Review gate: automated static review; repository-local commands were not executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants