Skip to content

Commit

Permalink
FIX: Decode brack-seperator value before splitting it with seperator
Browse files Browse the repository at this point in the history
The original implementation was splitting the received value before it
then decoded the value. Because the value was URL encoded, the split
function could not find the seperator to successfully split. Adjusted
the order of operations which fixes #388
  • Loading branch information
scottenock committed Sep 19, 2024
1 parent 4287e77 commit 8fb8114
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function parserForArrayFormat(options) {

const arrayValue = value === null
? []
: value.split(options.arrayFormatSeparator).map(item => decode(item, options));
: decode(value, options).split(options.arrayFormatSeparator)

Check failure on line 224 in base.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Missing semicolon.

Check failure on line 224 in base.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing semicolon.

if (accumulator[key] === undefined) {
accumulator[key] = arrayValue;
Expand Down
10 changes: 10 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ test('query strings having a brackets+separator array and format option as `brac
}), {foo: ['']});
});

test('query strings having a brackets+separator array and format option as `bracket-separator` with a URL encoded value', t => {
t.deepEqual(queryString.parse('?testA%5B%5D=1&testB%5B%5D=a%2Cb%2Cc%2Cd%2Ce%2Cf&testC=true', {
arrayFormat: 'bracket-separator',
}), {
testA: ['1'],
testB: ['a', 'b', 'c', 'd', 'e', 'f'],

Check failure on line 223 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Mixed spaces and tabs.

Check failure on line 223 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Mixed spaces and tabs.
testC: 'true',

Check failure on line 224 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Mixed spaces and tabs.

Check failure on line 224 in test/parse.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Mixed spaces and tabs.
});
});

test('query strings having = within parameters (i.e. GraphQL IDs)', t => {
t.deepEqual(queryString.parse('foo=bar=&foo=ba=z='), {foo: ['bar=', 'ba=z=']});
});
Expand Down

0 comments on commit 8fb8114

Please sign in to comment.