From 3b4c2959c0294a146eb48f7fa32f56d3e036008b Mon Sep 17 00:00:00 2001 From: plantainX Date: Sun, 12 Apr 2020 22:52:30 +0800 Subject: [PATCH 1/2] Fix value being decoded twice with `arrayFormat` option set to `separator` (#243) Co-authored-by: Sindre Sorhus --- index.js | 2 +- test/parse.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cad13ca..0b57b3e 100644 --- a/index.js +++ b/index.js @@ -246,7 +246,7 @@ function parse(input, options) { // Missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters - value = value === undefined ? null : options.arrayFormat === 'comma' ? value : decode(value, options); + value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options); formatter(decode(key, options), value, ret); } diff --git a/test/parse.js b/test/parse.js index 3c442e7..8964144 100644 --- a/test/parse.js +++ b/test/parse.js @@ -310,3 +310,16 @@ test('query strings having comma encoded and format option as `comma`', t => { ] }); }); + +test('value should not be decoded twice with `arrayFormat` option set as `separator`', t => { + t.deepEqual(queryString.parse('foo=2020-01-01T00:00:00%2B03:00', {arrayFormat: 'separator'}), { + foo: '2020-01-01T00:00:00+03:00' + }); +}); + +// See https://github.com/sindresorhus/query-string/issues/242 +test.failing('value separated by encoded comma will not be parsed as array with `arrayFormat` option set to `comma`', t => { + t.deepEqual(queryString.parse('id=1%2C2%2C3', {arrayFormat: 'comma', parseNumbers: true}), { + id: [1, 2, 3] + }); +}); From 3cd5d4d1ccfdaf127a1e8d1b8e0584b015f55e40 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 13 Apr 2020 00:17:37 +0800 Subject: [PATCH 2/2] 6.12.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2265152..d91178a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "query-string", - "version": "6.12.0", + "version": "6.12.1", "description": "Parse and stringify URL query strings", "license": "MIT", "repository": "sindresorhus/query-string",