Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
querystring: update logic in parse
  • Loading branch information
watilde committed Feb 4, 2017
commit b837c130d6332447ca8a1ad09cc322327f071a36
8 changes: 2 additions & 6 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function parse(qs, sep, eq, options) {
if (valEncoded)
value = decodeStr(value, decode);

if (key || value || lastPos - posIdx > sepLen || i === 0) {
if (key || value || lastPos - posIdx > sepLen) {
// Use a key array lookup instead of using hasOwnProperty(), which is
// slower
if (keys.indexOf(key) === -1) {
Expand All @@ -334,13 +334,9 @@ function parse(qs, sep, eq, options) {
// since we are generating all of the values being assigned.
if (curValue.pop)
curValue[curValue.length] = value;
else if (curValue)
else
obj[key] = [curValue, value];
}
} else if (i === 1) {
// A pair with repeated sep could be added into obj in the first loop
// and it should be deleted
delete obj[key];
}
if (--pairs === 0)
break;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const qsTestCases = [
['&=&=', '=&=', { '': [ '', '' ]}],
['a&&b', 'a=&b=', { 'a': '', 'b': '' }],
['a=a&&b=b', 'a=a&b=b', { 'a': 'a', 'b': 'b' }],
['&a', 'a=', { 'a': '' }],
['&=', '=', { '': '' }],
['a&a&', 'a=&a=', { a: [ '', '' ] }],
['a&a&a&', 'a=&a=&a=', { a: [ '', '', '' ] }],
['a&a&a&a&', 'a=&a=&a=&a=', { a: [ '', '', '', '' ] }],
[null, '', {}],
[undefined, '', {}]
];
Expand Down