Permalink
Browse files

Fix #3058 querystring: Fix incorrect handling of empty keys

  • Loading branch information...
1 parent 12fc9fa commit a811a4a13042a4b3ba019fbe1221f4c83b02a699 @isaacs isaacs committed May 11, 2012
Showing with 8 additions and 1 deletion.
  1. +5 −0 lib/querystring.js
  2. +3 −1 test/simple/test-querystring.js
View
@@ -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);
@@ -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 ]

0 comments on commit a811a4a

Please sign in to comment.