mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
querystring: fix value decoding after encoded keys
In the non-default parse() path, a key with more than one percent escape could corrupt non-ASCII characters in its value. Keep key characters out of the value's encoding check. Assisted-by: claude:opus-5.5 Signed-off-by: vedchaudhari <vedc2853@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66553 Refs: https://github.com/nodejs/node/pull/66175 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
1 parent
cab0d1fbf1
commit
3f0813199c
2 files changed
+14
-1
No files matched your search
+2
-1
@@ -555,8 +555,9 @@ function parse(qs, sep, eq, options) {
|
||||
key += StringPrototypeSlice(qs, lastPos, i);
|
||||
key += plusChar;
|
||||
lastPos = i + 1;
|
||||
continue;
|
||||
}
|
||||
// Don't let key characters affect value encoding.
|
||||
continue;
|
||||
}
|
||||
if (code === 43/* + */) {
|
||||
if (lastPos < i)
|
||||
|
||||
@@ -415,6 +415,18 @@ assert.strictEqual(qs.unescapeBuffer('a%%').toString(), 'a%%');
|
||||
// Test invalid encoded string
|
||||
check(qs.parse('%\u0100=%\u0101'), { '%Ā': '%ā' });
|
||||
|
||||
// Test encoded key with unencoded value
|
||||
{
|
||||
const input = '%C3%A4=caf\u00e9%';
|
||||
|
||||
check(
|
||||
qs.parse(input),
|
||||
{ '\u00e4': 'caf\u00e9%' });
|
||||
check(
|
||||
qs.parse(input, null, null),
|
||||
{ '\u00e4': 'caf\u00e9%' });
|
||||
}
|
||||
|
||||
// Test custom decode
|
||||
{
|
||||
function demoDecode(str) {
|
||||
|
||||
Reference in new issue
Block a user