diff --git a/lib/stringify.js b/lib/stringify.js index 7694988c..7ee8b7c3 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -48,7 +48,9 @@ var stringify = function stringify( // eslint-disable-line func-name-matching obj = filter(prefix, obj); } else if (obj instanceof Date) { obj = serializeDate(obj); - } else if (obj === null) { + } + + if (obj === null) { if (strictNullHandling) { return encoder && !encodeValuesOnly ? encoder(prefix) : prefix; } diff --git a/test/stringify.js b/test/stringify.js index 711dae50..8a4744b0 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -564,4 +564,25 @@ test('stringify()', function (t) { st.end(); }); + t.test('strictNullHandling works with custom filter', function (st) { + var filter = function (prefix, value) { + return value; + }; + + var options = { strictNullHandling: true, filter: filter }; + st.equal(qs.stringify({ key: null }, options), 'key'); + st.end(); + }); + + t.test('strictNullHandling works with null serializeDate', function (st) { + var serializeDate = function () { + return null; + }; + var options = { strictNullHandling: true, serializeDate: serializeDate }; + var date = new Date(); + st.equal(qs.stringify({ key: date }, options), 'key'); + st.end(); + }); + + t.end(); });