Skip to content

Commit 40c54a8

Browse files
committed
[Fix] parse: add tests for handling nested brackets and depth limits
1 parent 1bcf3ec commit 40c54a8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/parse.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,27 @@ test('parse()', function (t) {
276276
'preserves inner [] while still treating outer [] as array push'
277277
);
278278

279+
// Multiple nested bracket pairs: inner [] remains literal as part of the key
280+
st.deepEqual(
281+
qs.parse('a[b[c[]]]=d'),
282+
{ a: { 'b[c[]]': 'd' } },
283+
'treats "b[c[]]" as a literal key inside the bracket group'
284+
);
285+
286+
// Depth limits with literal brackets: preserve inner [] while limiting bracket-group parsing
287+
st.deepEqual(
288+
qs.parse('a[b[c[]]][d]=e', { depth: 1 }),
289+
{ a: { 'b[c[]]': { '[d]': 'e' } } },
290+
'respects depth: 1 and preserves literal inner [] in the parsed key'
291+
);
292+
293+
// Unterminated inner bracket group is wrapped as a literal remainder segment
294+
st.deepEqual(
295+
qs.parse('a[[]b=c'),
296+
{ a: { '[[]b': 'c' } },
297+
'handles unterminated inner bracket groups without throwing'
298+
);
299+
279300
st.end();
280301
});
281302

0 commit comments

Comments
 (0)