Skip to content

Commit

Permalink
Make QueryString.parse run faster
Browse files Browse the repository at this point in the history
Use decodeURIComponent when appropriate, and only fall back to
querystring.decode if it throws, or if the character is a '+'.

Fix nodejs#2248
  • Loading branch information
bluesmoon authored and isaacs committed Feb 2, 2012
1 parent 3deceaf commit 5166758
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,17 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq) {
}

qs.split(sep).forEach(function(kvp) {
var x = kvp.split(eq);
var k = QueryString.unescape(x[0], true);
var v = QueryString.unescape(x.slice(1).join(eq), true);
var x = kvp.split(eq), k, v, useQS=false;
try {
if (kvp.match(/\+/)) { // decodeURIComponent does not decode + to space
throw "has +";
}
k = decodeURIComponent(x[0]);
v = decodeURIComponent(x.slice(1).join(eq) || "");
} catch(e) {
k = QueryString.unescape(x[0], true);
v = QueryString.unescape(x.slice(1).join(eq), true);
}

if (!hasOwnProperty(obj, k)) {
obj[k] = v;
Expand Down

0 comments on commit 5166758

Please sign in to comment.