Skip to content

Commit daf3e6a

Browse files
committed
[Fix] stringify: when arrayFormat is comma, respect serializeDate
Fixes #364.
1 parent 47e5f8b commit daf3e6a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/stringify.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ var stringify = function stringify(
7575
} else if (obj instanceof Date) {
7676
obj = serializeDate(obj);
7777
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
78-
obj = obj.join(',');
78+
obj = utils.maybeMap(obj, function (value) {
79+
if (value instanceof Date) {
80+
return serializeDate(value);
81+
}
82+
return value;
83+
}).join(',');
7984
}
8085

8186
if (obj === null) {

test/stringify.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,18 @@ test('stringify()', function (t) {
595595
'custom serializeDate function called'
596596
);
597597

598+
st.equal(
599+
qs.stringify(
600+
{ a: [date] },
601+
{
602+
serializeDate: function (d) { return d.getTime(); },
603+
arrayFormat: 'comma'
604+
}
605+
),
606+
'a=' + date.getTime(),
607+
'works with arrayFormat comma'
608+
);
609+
598610
st.end();
599611
});
600612

0 commit comments

Comments
 (0)