mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
querystring: do not add sep for empty array
Currently, stringification of an empty array outputs a single separator character. This commit causes an empty array to output the empty string. Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
e1ce8ba639
commit
61ddad1314
2 changed files with 18 additions and 12 deletions
|
@ -128,9 +128,6 @@ var stringifyPrimitive = function(v) {
|
|||
QueryString.stringify = QueryString.encode = function(obj, sep, eq, options) {
|
||||
sep = sep || '&';
|
||||
eq = eq || '=';
|
||||
if (util.isNull(obj)) {
|
||||
obj = undefined;
|
||||
}
|
||||
|
||||
var encode = QueryString.escape;
|
||||
if (options && typeof options.encodeURIComponent === 'function') {
|
||||
|
@ -138,16 +135,22 @@ QueryString.stringify = QueryString.encode = function(obj, sep, eq, options) {
|
|||
}
|
||||
|
||||
if (util.isObject(obj)) {
|
||||
return Object.keys(obj).map(function(k) {
|
||||
var keys = Object.keys(obj);
|
||||
var fields = [];
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var k = keys[i];
|
||||
var v = obj[k];
|
||||
var ks = encode(stringifyPrimitive(k)) + eq;
|
||||
if (util.isArray(obj[k])) {
|
||||
return obj[k].map(function(v) {
|
||||
return ks + encode(stringifyPrimitive(v));
|
||||
}).join(sep);
|
||||
|
||||
if (util.isArray(v)) {
|
||||
for (var j = 0; j < v.length; j++)
|
||||
fields.push(ks + encode(stringifyPrimitive(v[j])));
|
||||
} else {
|
||||
return ks + encode(stringifyPrimitive(obj[k]));
|
||||
fields.push(ks + encode(stringifyPrimitive(v)));
|
||||
}
|
||||
}).join(sep);
|
||||
}
|
||||
return fields.join(sep);
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue