Fix #3058 querystring: Fix incorrect handling of empty keys

This commit is contained in:
isaacs 2012-05-11 08:49:03 -07:00
parent 12fc9fa8a7
commit a811a4a130
2 changed files with 8 additions and 1 deletions

View File

@ -189,6 +189,11 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
kstr = x.substring(0, idx),
vstr = x.substring(idx + 1), k, v;
if (kstr === '' && vstr !== '') {
kstr = vstr;
vstr = '';
}
try {
k = decodeURIComponent(kstr);
v = decodeURIComponent(vstr);

View File

@ -55,7 +55,9 @@ var qsTestCases = [
{ hasOwnProperty: 'x',
toString: 'foo',
valueOf: 'bar',
__defineGetter__: 'baz' }]
__defineGetter__: 'baz' }],
// See: https://github.com/joyent/node/issues/3058
['foo&bar=baz', 'foo=&bar=baz', { foo: '', bar: 'baz' }]
];
// [ wonkyQS, canonicalQS, obj ]