Skip to content

Commit

Permalink
Support stringifying array containing value 0 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
padupuy authored and sindresorhus committed Apr 28, 2019
1 parent 64a30da commit 317cb36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 317cb36

Please sign in to comment.