From 3f0813199c7f1b2d6bdda8f32b4e067d4495ce08 Mon Sep 17 00:00:00 2001 From: Ved Chaudhari <84765263+vedchaudhari@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:18:55 +0530 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/66553 Refs: https://github.com/nodejs/node/pull/66175 Reviewed-By: Yagiz Nizipli --- lib/querystring.js | 3 ++- test/parallel/test-querystring.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/querystring.js b/lib/querystring.js index 6aca65dee5b..c6dc1afcf5f 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -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) diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index b24ec5b569b..ec463e4a45b 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -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) {