Skip to content

Commit

Permalink
Fix using the parseNumbers and parseBooleans options together (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixoi authored and sindresorhus committed Jun 21, 2019
1 parent a8710eb commit 90eb40e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ function parse(input, options) {

if (options.parseNumbers && !Number.isNaN(Number(value))) {
value = Number(value);
}

if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
value = value.toLowerCase() === 'true';
}

Expand Down
5 changes: 5 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,8 @@ test('boolean value returns as boolean if option is set', t => {
t.deepEqual(queryString.parse('foo=true', {parseBooleans: true}), {foo: true});
t.deepEqual(queryString.parse('foo=false&bar=true', {parseBooleans: true}), {foo: false, bar: true});
});

test('boolean value returns as boolean and number value as number if both options are set', t => {
t.deepEqual(queryString.parse('foo=true&bar=1.12', {parseNumbers: true, parseBooleans: true}), {foo: true, bar: 1.12});
t.deepEqual(queryString.parse('foo=16.32&bar=false', {parseNumbers: true, parseBooleans: true}), {foo: 16.32, bar: false});
});

0 comments on commit 90eb40e

Please sign in to comment.