From a811a4a13042a4b3ba019fbe1221f4c83b02a699 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 11 May 2012 08:49:03 -0700 Subject: [PATCH] Fix #3058 querystring: Fix incorrect handling of empty keys --- lib/querystring.js | 5 +++++ test/simple/test-querystring.js | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) 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 ]