-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Parse int pipe improvement #385
Parse int pipe improvement #385
Conversation
Hi @oschweitzer, thanks for PR! |
Sure you're right, I propose to change the condition to: if ('string' === typeof value && !isNaN(parseFloat(value)) && isFinite(value as any)) {
return parseInt(value, 10);
} And therefore to remove the rxjs import, is it ok for you ? |
@oschweitzer sounds good! |
This commit also removes the unused rxjs import
Great job @oschweitzer! Thanks 🙂 |
this will map the following to the same value: |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
TLDR; This PR improves the ParseIntPipe validation.
Motivation
Take the following code base:
If a user sends the following HTTP request
GET http://localhost:3000/users/1abc
, the current parseIntPipe will validate the parameter. I think it's not the expected behaviour.Proposal
This PR will improve the parseIntPipe by using the
rxjs
functionisNumeric
to be sure that the input string is only composed of numbers.rxjs
being already a dependency ofnestjs
, this PR doesn't add a new dependency.