Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/types/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ module.exports = Any.extend({
}

if (typeof value === 'string') {
const normalized = schema._flags.sensitive ? value : value.toLowerCase();
const trimmedValue = value.trim();
const normalized = schema._flags.sensitive ? trimmedValue : trimmedValue.toLowerCase();
value = normalized === 'true' ? true : (normalized === 'false' ? false : value);
}

Expand Down
8 changes: 8 additions & 0 deletions test/types/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ describe('boolean', () => {
]);
});

it('converts boolean string with trailing spaces to a boolean', () => {

Helper.validate(Joi.boolean(), [
['true ', true, true],
['false ', true, false]
]);
});

it('does not convert boolean string to a boolean in strict mode', () => {

Helper.validate(Joi.boolean().strict(), [
Expand Down