Skip to content

Commit 73b37ad

Browse files
committed
FEAT: boolean type accepts an empty string as true
1 parent a277921 commit 73b37ad

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ function parseValue(value, options, type) {
309309
return type(value);
310310
}
311311

312+
if (type === 'boolean' && value === null) {
313+
return true;
314+
}
315+
312316
if (type === 'boolean' && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
313317
return value.toLowerCase() === 'true';
314318
}

test/parse.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,19 @@ test('types option: boolean type accepts 1 and 0 as boolean values', t => {
592592
b: false,
593593
});
594594
});
595+
596+
test('types option: boolean type accepts an empty string as true', t => {
597+
t.deepEqual(
598+
queryString.parse('a&b', {
599+
parsebooleans: false,
600+
types: {
601+
a: 'boolean',
602+
b: 'boolean',
603+
},
604+
}),
605+
{
606+
a: true,
607+
b: true,
608+
},
609+
);
610+
});

0 commit comments

Comments
 (0)