Fix #3058 querystring: Fix incorrect handling of empty keys
authorisaacs <i@izs.me>
Fri, 11 May 2012 15:49:03 +0000 (08:49 -0700)
committerisaacs <i@izs.me>
Fri, 11 May 2012 15:49:03 +0000 (08:49 -0700)
lib/querystring.js
test/simple/test-querystring.js

index 7aa6e84..3c03cf3 100644 (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);
index 0764481..2d86625 100644 (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 ]