diff --git a/lib/querystring.js b/lib/querystring.js index 7aa6e844b9..3c03cf313e 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -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); diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js index 0764481cb8..2d86625f32 100644 --- a/test/simple/test-querystring.js +++ b/test/simple/test-querystring.js @@ -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 ]