Skip to content

Commit

Permalink
Merge pull request #13 from cdeutsch/sync-query-string-v6.12.1
Browse files Browse the repository at this point in the history
Sync query string v6.12.1
  • Loading branch information
cdeutsch authored Apr 13, 2020
2 parents a913805 + a6aae89 commit da83806
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function parse(input, options) {
// 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);
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-string-for-all",
"version": "6.12.0",
"version": "6.12.1",
"description": "Parse and stringify URL query strings",
"license": "MIT",
"repository": "cdeutsch/query-string-for-all",
Expand Down
13 changes: 13 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
});
});

0 comments on commit da83806

Please sign in to comment.