-
Notifications
You must be signed in to change notification settings - Fork 511
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leepood, could you please rebase with the current develop and address the changes requested here?
} | ||
if (value === 'false' || value === '0' || value ==='no') { | ||
return false; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I vote against having this in class-transformer as this is out of scope for this project. In JSON a Checking whether the received value is valid or not is task for class-validator not class-transformer. |
This issue is somewhat related to #363. |
@NoNameProvided If I'm transforming query parameters into a class, which are all string values, I would not expect The documentation has several references to parsing values from strings. For example
So if the answer is, "this is not how it should work", then how it should work needs to be clarified with an explicit example. Right now, I'm not sure I understand why transforming a string to a boolean is the responsibility of the validator library and not the transformer library. |
The referenced documentation is valid, because
The transformer library must does not know anything about the content of the received payload. It should just try to convert it to the desired target type. For your scenario a possible workaround can be to send empty query params However, I understand your scenario and I agree this is not a good approach to tackle this problem. Currently, the only solution I see is to add a flag that enables this conversion, however this is the scenario I am trying to avoid. We will clean up a repo a little bit and will return to this issue and figure out how to go forward. |
This won't be the accepted approach. The solution will be a decorator based approach defined here: #550. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
#306