Skip to content

Commit

Permalink
Bug Fix for istrue & isfalse utility function (#1099)
Browse files Browse the repository at this point in the history
* `bug`: fixed isTrue & isFalse error
+ when a number is ecountered isTrue and isFalse return error
+ now fixed

* `improve`: added new test cases to verify
  • Loading branch information
JosephVoid authored Mar 17, 2024
1 parent e610ed1 commit 3420238
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/util/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const sanitize = require('sanitize-filename');
// REQUEST PARSING

// Returns t/f only if the input is a string of any upper/lowercase combination.
const isTrue = (x) => (!isBlank(x) && (x.toLowerCase() === 'true'));
const isFalse = (x) => (!isBlank(x) && (x.toLowerCase() === 'false'));
const isTrue = (x) => (!isBlank(x) && typeof x === 'string' && (x.toLowerCase() === 'true'));
const isFalse = (x) => (!isBlank(x) && typeof x === 'string' && (x.toLowerCase() === 'false'));

// Returns just the pathname of the URL, omitting querystring and other non-path decoration.
const urlPathname = (x) => parse(x).pathname;
Expand Down
19 changes: 19 additions & 0 deletions test/unit/util/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ describe('util/http', () => {
isTrue('').should.equal(false);
isTrue(null).should.equal(false);
isTrue(undefined).should.equal(false);
isTrue(2).should.equal(false);
});
});

describe('isFalse', () => {
const { isFalse } = http;
it('should return true for falsey strings', () => {
isFalse('FALSE').should.equal(true);
isFalse('False').should.equal(true);
isFalse('false').should.equal(true);
});

it('should return false for all other values', () => {
isFalse('no').should.equal(false);
isFalse('off').should.equal(false);
isFalse('').should.equal(false);
isFalse(null).should.equal(false);
isFalse(undefined).should.equal(false);
isFalse(2).should.equal(false);
});
});

Expand Down

0 comments on commit 3420238

Please sign in to comment.