Skip to content

Commit

Permalink
querystring: fix stringify for empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
sapics committed Jun 19, 2020
1 parent 343cf1b commit a117ec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function stringify(obj, sep, eq, options) {
if (obj !== null && typeof obj === 'object') {
const keys = ObjectKeys(obj);
const len = keys.length;
const flast = len - 1;
let fields = '';
for (let i = 0; i < len; ++i) {
const k = keys[i];
Expand All @@ -207,20 +206,20 @@ function stringify(obj, sep, eq, options) {
if (ArrayIsArray(v)) {
const vlen = v.length;
if (vlen === 0) continue;
const vlast = vlen - 1;
if (fields)
fields += sep;
for (let j = 0; j < vlen; ++j) {
if (j)
fields += sep;
fields += ks;
fields += convert(v[j], encode);
if (j < vlast)
fields += sep;
}
} else {
if (fields)
fields += sep;
fields += ks;
fields += convert(v, encode);
}

if (i < flast)
fields += sep;
}
return fields;
}
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ const qsWeirdObjects = [
[{ n: null }, 'n=', { 'n': '' }],
[{ nan: NaN }, 'nan=', { 'nan': '' }],
[{ inf: Infinity }, 'inf=', { 'inf': '' }],
[{ a: [], b: [] }, '', {}]
[{ a: [], b: [] }, '', {}],
[{ a: 1, b: [] }, 'a=1', { 'a': '1' }]
];
// }}}

Expand Down

0 comments on commit a117ec5

Please sign in to comment.