-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
fix(common): enforce string type in validationpipe #14241
fix(common): enforce string type in validationpipe #14241
Conversation
strictly parse the value to string to avoid nested objects being passed if the type is explicitly set to string closes nestjs#14234
Pull Request Test Coverage Report for Build 235ee298-c027-4827-8b3d-0f52882777ecDetails
💛 - Coveralls |
@@ -207,6 +207,9 @@ export class ValidationPipe implements PipeTransform<any> { | |||
return +value; | |||
} | |||
if (metatype === String) { |
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.
if (metatype === String) { | |
if (metatype === String && !isUndefined(value)) { |
@@ -207,6 +207,9 @@ export class ValidationPipe implements PipeTransform<any> { | |||
return +value; | |||
} | |||
if (metatype === String) { | |||
if (isUndefined(value)) { |
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.
this nested if can be removed then
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.
I did this for sake of consistency, but changed it to the suggested implementation
lgtm |
strictly parse the value to string to avoid nested objects being passed if the type is explicitly set to string.
The solution was already provided in the issue, I thought I could quickly submit a PR :) , however I didnt include the part for empty value, because if the value is set to string type and an empty value is provided, it should just return an empty string, it will be useful in some cases.
closes #14234
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The pipeline doesnt pass the value to string if an nested object is provided and the type is explicitly set to string.
Issue Number: #14234
What is the new behavior?
if the value of foo query set to string, it will parse it to string no matter the value.
Does this PR introduce a breaking change?
Other information