From a6d3530855f7793a899540a839defd748b888c69 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Sat, 4 Feb 2017 22:53:20 +0100 Subject: [PATCH] querystring: fix state machine in querystring.parse - posIdx should save the current position instead of the last position. Fixed cases: - `a&&b` => `{ 'a': '', 'b': '' }` - `a=a&&b=b` => `{ 'a': 'a', 'b': 'b' }` Fixes https://github.com/nodejs/node/issues/10454 --- lib/querystring.js | 2 +- test/parallel/test-querystring.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/querystring.js b/lib/querystring.js index 9b4ca27640aa71..3dc338b0d5c8b0 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -347,7 +347,7 @@ function parse(qs, sep, eq, options) { keyEncoded = valEncoded = customDecode; encodeCheck = 0; key = value = ''; - posIdx = lastPos; + posIdx = i; lastPos = i + 1; sepIdx = eqIdx = 0; } diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index baa426094c77c6..b35cc68df9d7c7 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -59,6 +59,8 @@ const qsTestCases = [ ['&&&&', '', {}], ['&=&', '=', { '': '' }], ['&=&=', '=&=', { '': [ '', '' ]}], + ['a&&b', 'a=&b=', { 'a': '', 'b': '' }], + ['a=a&&b=b', 'a=a&b=b', { 'a': 'a', 'b': 'b' }], [null, '', {}], [undefined, '', {}] ];