Skip to content

Commit

Permalink
[Fix] stringify: when arrayFormat is comma, respect `serializeD…
Browse files Browse the repository at this point in the history
…ate`

Fixes #364.
  • Loading branch information
ljharb committed May 2, 2020
1 parent 47e5f8b commit daf3e6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ var stringify = function stringify(
} else if (obj instanceof Date) {
obj = serializeDate(obj);
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
obj = obj.join(',');
obj = utils.maybeMap(obj, function (value) {
if (value instanceof Date) {
return serializeDate(value);
}
return value;
}).join(',');
}

if (obj === null) {
Expand Down
12 changes: 12 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,18 @@ test('stringify()', function (t) {
'custom serializeDate function called'
);

st.equal(
qs.stringify(
{ a: [date] },
{
serializeDate: function (d) { return d.getTime(); },
arrayFormat: 'comma'
}
),
'a=' + date.getTime(),
'works with arrayFormat comma'
);

st.end();
});

Expand Down

0 comments on commit daf3e6a

Please sign in to comment.