Skip to content

fix: fix the issue when 'false' convert to boolean always true #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions src/TransformOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export class TransformOperationExecutor {
} else if (targetType === Boolean && !isMap) {
if (value === null || value === undefined)
return value;
if (value === 'true' || value === '1' || value === 'yes') {
return true;
}
if (value === 'false' || value === '0' || value ==='no') {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes/no is a bit too much. I recommend to remove them.

Please also remove the {}s, the rest of the code does not have them for single line if statements.

We also need some tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may check the tests from this PR if you need ideas.

return Boolean(value);

} else if ((targetType === Date || value instanceof Date) && !isMap) {
Expand Down