query-string
Advanced tools
Comparing version 3.0.3 to 4.0.0
34
index.js
@@ -9,4 +9,8 @@ 'use strict'; | ||
exports.parse = function (str) { | ||
// Create an object with no prototype | ||
// https://github.com/sindresorhus/query-string/issues/47 | ||
var ret = Object.create(null); | ||
if (typeof str !== 'string') { | ||
return {}; | ||
return ret; | ||
} | ||
@@ -17,6 +21,6 @@ | ||
if (!str) { | ||
return {}; | ||
return ret; | ||
} | ||
return str.split('&').reduce(function (ret, param) { | ||
str.split('&').forEach(function (param) { | ||
var parts = param.replace(/\+/g, ' ').split('='); | ||
@@ -34,3 +38,3 @@ // Firefox (pre 40) decodes `%3D` to `=` | ||
if (!ret.hasOwnProperty(key)) { | ||
if (ret[key] !== undefined) { | ||
ret[key] = val; | ||
@@ -42,5 +46,5 @@ } else if (Array.isArray(ret[key])) { | ||
} | ||
}); | ||
return ret; | ||
}, {}); | ||
return ret; | ||
}; | ||
@@ -61,5 +65,17 @@ | ||
if (Array.isArray(val)) { | ||
return val.slice().sort().map(function (val2) { | ||
return strictUriEncode(key) + '=' + strictUriEncode(val2); | ||
}).join('&'); | ||
var result = []; | ||
val.slice().sort().forEach(function (val2) { | ||
if (val2 === undefined) { | ||
return; | ||
} | ||
if (val2 === null) { | ||
result.push(strictUriEncode(key)); | ||
} else { | ||
result.push(strictUriEncode(key) + '=' + strictUriEncode(val2)); | ||
} | ||
}); | ||
return result.join('&'); | ||
} | ||
@@ -66,0 +82,0 @@ |
{ | ||
"name": "query-string", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"description": "Parse and stringify URL query strings", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -48,2 +48,4 @@ # query-string [![Build Status](https://travis-ci.org/sindresorhus/query-string.svg?branch=master)](https://travis-ci.org/sindresorhus/query-string) | ||
The returned object is created with [`Object.create(null)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) and thus does not have a `prototype`. | ||
### .stringify(*object*) | ||
@@ -50,0 +52,0 @@ |
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
5478
64
79