From 317cb364d873f325c20d16059c43f36adefefa8c Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Dupuy Date: Sun, 28 Apr 2019 10:53:17 +0200 Subject: [PATCH] Support stringifying array containing value 0 (#173) --- index.js | 2 +- test/stringify.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 78f0f919..ba23c364 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ function encoderForArrayFormat(options) { case 'comma': return key => (result, value, index) => { - if (!value) { + if (value === null || value === undefined || value.length === 0) { return result; } diff --git a/test/stringify.js b/test/stringify.js index 6e6b63ca..8553ebd6 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -135,6 +135,15 @@ test('array stringify representation with array commas and null value', t => { }), 'foo=a'); }); +test('array stringify representation with array commas and 0 value', t => { + t.is(queryString.stringify({ + foo: ['a', null, 0], + bar: [null] + }, { + arrayFormat: 'comma' + }), 'foo=a,0'); +}); + test('array stringify representation with a bad array format', t => { t.is(queryString.stringify({ foo: null,