Skip to content

Commit b38f06c

Browse files
authoredOct 17, 2020
When only receiving values with encoded array value, decode values (#287)
1 parent 6427722 commit b38f06c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
 

‎index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ function parserForArrayFormat(options) {
122122
case 'comma':
123123
case 'separator':
124124
return (key, value, accumulator) => {
125-
const isArray = typeof value === 'string' && value.split('').indexOf(options.arrayFormatSeparator) > -1;
126-
const newValue = isArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
125+
const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
126+
const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
127+
value = isEncodedArray ? decode(value, options) : value;
128+
const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
127129
accumulator[key] = newValue;
128130
};
129131

‎test/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ test('value should not be decoded twice with `arrayFormat` option set as `separa
323323
});
324324

325325
// See https://github.com/sindresorhus/query-string/issues/242
326-
test.failing('value separated by encoded comma will not be parsed as array with `arrayFormat` option set to `comma`', t => {
326+
test('value separated by encoded comma will not be parsed as array with `arrayFormat` option set to `comma`', t => {
327327
t.deepEqual(queryString.parse('id=1%2C2%2C3', {arrayFormat: 'comma', parseNumbers: true}), {
328328
id: [1, 2, 3]
329329
});

0 commit comments

Comments
 (0)
Please sign in to comment.