diff --git a/tests/unit/RequestValidator.ts b/tests/unit/RequestValidator.ts index 3be1c31..2af21b0 100644 --- a/tests/unit/RequestValidator.ts +++ b/tests/unit/RequestValidator.ts @@ -76,6 +76,22 @@ describe('RequestValidator', () => { null, test ); + expected = 'Url: Param foo has invalid type (boolean)'; + validator.validate( + { + route: { + validation: { + url: { + foo: {type: 'boolean'} + } + } + }, params: { + foo: 'bar' + } + }, + null, test + ); + expected = undefined; validator.validate( { diff --git a/ts/RequestValidator.ts b/ts/RequestValidator.ts index 27b574d..ef6c37c 100644 --- a/ts/RequestValidator.ts +++ b/ts/RequestValidator.ts @@ -315,7 +315,11 @@ export class RequestValidator { } return isNumeric; } else if (typeValidation.type === 'boolean') { - return ['0', '1', 'false', 'true', false, true, 0, 1].indexOf(typeValidation.value) !== -1; + const isBoolean = ['0', '1', 'false', 'true', false, true, 0, 1].indexOf(typeValidation.value) !== -1; + if (isBoolean === true) { + typeValidation.value = ['1', 'true', true, 1].indexOf(typeValidation.value) !== -1; + } + return isBoolean; } else if (typeValidation.type === 'date') { if (typeof typeValidation.value === 'object' && typeof typeValidation.value.getTime === 'function') { return true;