Skip to content

Commit 3a8b94a

Browse files
committed
[Tests] add regression tests for keys containing percent-encoded bracket text
Locks in the round-trip and direct-parse behavior for keys containing literal %5B, %5D, %255B, and %255D text.
1 parent 96755ab commit 3a8b94a

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/stringify.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,4 +1316,33 @@ test('stringifies empty keys', function (t) {
13161316

13171317
st.end();
13181318
});
1319+
1320+
t.test('round-trips keys containing percent-encoded bracket text', function (st) {
1321+
var cases = [
1322+
{ 'a%5Bb': 'c' },
1323+
{ 'a%5Db': 'c' },
1324+
{ 'a%255Bb': 'c' },
1325+
{ 'a%255Db': 'c' },
1326+
{ a: { 'b%5Bc': 'd' } },
1327+
{ a: { 'b%255Bc': 'd' } },
1328+
{ 'a%5B%255Bb': 'c' }
1329+
];
1330+
for (var i = 0; i < cases.length; i++) {
1331+
st.deepEqual(
1332+
qs.parse(qs.stringify(cases[i])),
1333+
cases[i],
1334+
'round-trips ' + JSON.stringify(cases[i])
1335+
);
1336+
}
1337+
1338+
st.end();
1339+
});
1340+
1341+
t.test('parses input containing percent-encoded bracket text without mangling', function (st) {
1342+
st.deepEqual(qs.parse('a%25255Bb=c'), { 'a%255Bb': 'c' }, 'a%25255Bb decodes to a%255Bb, not a%5Bb');
1343+
st.deepEqual(qs.parse('a%25255Db=c'), { 'a%255Db': 'c' }, 'a%25255Db decodes to a%255Db, not a%5Db');
1344+
st.deepEqual(qs.parse('a%5Bb%25255Bc%5D=d'), { a: { 'b%255Bc': 'd' } }, 'nested %25255B decodes to %255B inside segment, not %5B');
1345+
1346+
st.end();
1347+
});
13191348
});

0 commit comments

Comments
 (0)