Make QueryString.parse run faster
Use decodeURIComponent when appropriate, and only fall back to querystring.decode if it throws, or if the character is a '+'. Fix #2248
This commit is contained in:
parent
3deceaf6e7
commit
5166758927
@ -170,9 +170,17 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
qs.split(sep).forEach(function(kvp) {
|
qs.split(sep).forEach(function(kvp) {
|
||||||
var x = kvp.split(eq);
|
var x = kvp.split(eq), k, v, useQS=false;
|
||||||
var k = QueryString.unescape(x[0], true);
|
try {
|
||||||
var v = QueryString.unescape(x.slice(1).join(eq), true);
|
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)) {
|
if (!hasOwnProperty(obj, k)) {
|
||||||
obj[k] = v;
|
obj[k] = v;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user