Skip to content

Commit

Permalink
fix(common): when transforming invalid boolean values
Browse files Browse the repository at this point in the history
on `ValidationPipe`, it must not return a valid boolean
  • Loading branch information
micalevisk committed Jan 26, 2023
1 parent bcf4bf9 commit 5f5fe8b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/common/pipes/validation.pipe.ts
Expand Up @@ -179,6 +179,12 @@ export class ValidationPipe implements PipeTransform<any> {
return value;
}
if (metatype === Boolean) {
if (typeof value === 'undefined') {
// This is an workaround to deal with optional boolean values since
// the default value of an optional boolean shouldn't be a valid boolean
return undefined;
}
// Any fasly value but `undefined` will be parsed to `false`
return value === true || value === 'true';
}
if (metatype === Number) {
Expand Down

0 comments on commit 5f5fe8b

Please sign in to comment.