diff options
author | cjihrig <cjihrig@gmail.com> | 2014-07-19 01:27:34 -0400 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2014-07-24 00:41:51 +0400 |
commit | 61ddad1314824ac32bb2eadd88c44df53ab4792c (patch) | |
tree | 356636d292fb34a68329d0e01e243965506322a5 /lib/querystring.js | |
parent | e1ce8ba639b5591675a43859697b00b9134e30ec (diff) | |
download | android-node-v8-61ddad1314824ac32bb2eadd88c44df53ab4792c.tar.gz android-node-v8-61ddad1314824ac32bb2eadd88c44df53ab4792c.tar.bz2 android-node-v8-61ddad1314824ac32bb2eadd88c44df53ab4792c.zip |
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>
Diffstat (limited to 'lib/querystring.js')
-rw-r--r-- | lib/querystring.js | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/querystring.js b/lib/querystring.js index aa3f3c7368..369316c203 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -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 ''; }; |