Skip to content

Commit

Permalink
Only parse + to space when decode is true (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anusien authored and sindresorhus committed Nov 13, 2019
1 parent 20d8069 commit e20ab65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
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
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 e20ab65

Please sign in to comment.