Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Decode back-separator value before splitting it with separator #392

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

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', {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the string to be unencoded, and encode it before passing it to parse. This makes it possible to actually see what it contains when reading the code.

arrayFormat: 'bracket-separator',
}), {
testA: ['1'],
testB: ['a', 'b', 'c', 'd', 'e', 'f'],
testC: 'true',
});
});

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