Skip to content

Commit

Permalink
querystring: fix state machine in querystring.parse
Browse files Browse the repository at this point in the history
- posIdx should save the current position instead of the last position.

Fixed cases:
- `a&&b` => `{ 'a': '', 'b': '' }`
- `a=a&&b=b` => `{ 'a': 'a', 'b': 'b' }`

Fixes nodejs#10454
  • Loading branch information
watilde committed Feb 4, 2017
1 parent 8b04bc9 commit a6d3530
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function parse(qs, sep, eq, options) {
keyEncoded = valEncoded = customDecode;
encodeCheck = 0;
key = value = '';
posIdx = lastPos;
posIdx = i;
lastPos = i + 1;
sepIdx = eqIdx = 0;
}
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const qsTestCases = [
['&&&&', '', {}],
['&=&', '=', { '': '' }],
['&=&=', '=&=', { '': [ '', '' ]}],
['a&&b', 'a=&b=', { 'a': '', 'b': '' }],
['a=a&&b=b', 'a=a&b=b', { 'a': 'a', 'b': 'b' }],
[null, '', {}],
[undefined, '', {}]
];
Expand Down

0 comments on commit a6d3530

Please sign in to comment.