isomorphic-querystring
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -39,53 +39,57 @@ function stringify( | ||
const length = str.length; | ||
if (length === 0) return result; | ||
let key = ""; | ||
let keyOrValue = 0; | ||
let parsedKeys = 0; | ||
let state = 0; | ||
let value = ""; | ||
if (str.length === 0) return result; | ||
for (let i = 0; i <= length; i++) { | ||
const char = str[i]; | ||
for (let i = 0; i <= length; i++) { | ||
if (parsedKeys >= maxKeys) { | ||
break; | ||
if (char === undefined) { | ||
state = 2; | ||
} | ||
const char = str[i]; | ||
switch (char) { | ||
case eq: | ||
if (!(decodeURIComponent(key) in result)) { | ||
result[decodeURIComponent(key)] = undefined; | ||
} | ||
parsedKeys += 1; | ||
keyOrValue = 1; | ||
break; | ||
case undefined: | ||
case sep: | ||
if (Array.isArray(result[decodeURIComponent(key)])) { | ||
// concat array | ||
result[decodeURIComponent(key)].concat(decodeURIComponent(value)); | ||
} else if (result[decodeURIComponent(key)] !== undefined) { | ||
// turn into array | ||
result[decodeURIComponent(key)] = [ | ||
result[decodeURIComponent(key)] | ||
].concat(decodeURIComponent(value)); | ||
switch (state) { | ||
case 0: | ||
if (char !== eq) { | ||
key += char; | ||
} else { | ||
// set value | ||
result[decodeURIComponent(key)] = decodeURIComponent(value); | ||
if (!(decodeURIComponent(key) in result)) { | ||
result[decodeURIComponent(key)] = undefined; | ||
} | ||
state = 1; | ||
parsedKeys += 1; | ||
} | ||
key = ""; | ||
value = ""; | ||
keyOrValue = 0; | ||
break; | ||
default: | ||
if (keyOrValue === 1) { | ||
case 1: | ||
case 2: | ||
if (char !== sep && char !== undefined) { | ||
value += char; | ||
} else { | ||
key += char; | ||
if (Array.isArray(result[decodeURIComponent(key)])) { | ||
// concat array | ||
result[decodeURIComponent(key)].concat(decodeURIComponent(value)); | ||
} else if (result[decodeURIComponent(key)] !== undefined) { | ||
// turn into array | ||
result[decodeURIComponent(key)] = [ | ||
result[decodeURIComponent(key)] | ||
].concat(decodeURIComponent(value)); | ||
} else { | ||
// set value | ||
result[decodeURIComponent(key)] = decodeURIComponent(value); | ||
} | ||
key = ""; | ||
value = ""; | ||
state = 0; | ||
} | ||
break; | ||
} | ||
if (maxKeys !== 0 && parsedKeys > maxKeys) { | ||
break; | ||
} | ||
} | ||
return result; | ||
@@ -92,0 +96,0 @@ } |
{ | ||
"name": "isomorphic-querystring", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"license": "MIT", | ||
@@ -17,3 +17,4 @@ "description": "isomorphic querystring interface for client & server.", | ||
"devDependencies": { | ||
"jest": "24.8.0" | ||
"jest": "24.8.0", | ||
"jest-in-case": "1.0.2" | ||
}, | ||
@@ -20,0 +21,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3236
101
2