Skip to content

Commit

Permalink
Only parse '+' to ' ' when decode is true (sindresorhus#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anusien committed Oct 3, 2019
1 parent de0536a commit 869e7c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function parse(input, options) {
}

for (const param of input.split('&')) {
let [key, value] = splitOnFirst(param.replace(/\+/g, ' '), '=');
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');

// Missing `=` should be `null`:
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
Expand Down
4 changes: 4 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ test('handle `+` correctly', t => {
t.deepEqual(queryString.parse('foo+faz=bar+baz++'), {'foo faz': 'bar baz '});
});

test('handle `+` correctly when not decoding', t => {
t.deepEqual(queryString.parse('foo+faz=bar+baz++', {decode: false}), {'foo+faz': 'bar+baz++'});
});

test('handle multiple of the same key', t => {
t.deepEqual(queryString.parse('foo=bar&foo=baz'), {foo: ['bar', 'baz']});
});
Expand Down

0 comments on commit 869e7c4

Please sign in to comment.