Created
May 11, 2012 15:49
-
-
Save isaacs/2660566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit a811a4a13042a4b3ba019fbe1221f4c83b02a699 | |
Author: isaacs <i@izs.me> | |
Date: Fri May 11 08:49:03 2012 -0700 | |
Fix #3058 querystring: Fix incorrect handling of empty keys | |
diff --git a/lib/querystring.js b/lib/querystring.js | |
index 7aa6e84..3c03cf3 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 0764481..2d86625 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 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment