-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Incorrect validation result when passing explicit undefined in options to isInt #1532
Comments
This also checks for let minCheckPassed = (!options.hasOwnProperty('min') || !options.min || str >= options.min); @profnandaa what do you think? Should I submit a PR? |
That would however fail for A parseInt or typeof may be sufficient. |
Right, I haven't thought about that. However const minCheckPassed = (
options.min === null ||
typeof options.min === 'undefined' ||
str >= options.min
) |
@fedeci are you still willing to open a PR for this use-case/fix? |
Sure! |
Go ahead and raise a Pr for this fix and tag the issue. @profnandaa, @tux-tn, and @rubiin what do you think? |
I think this should be fixed as well |
Describe the bug
Due to my use case I'm currently wrapping the isInt validator and passing the options object as required. In conformance with the typescript type definitions I'm explicitly passing undefined for
options.max
. Because isInt uses hasOwnProperty to check for the presence of the option it compares the value with undefined and the validation fails.As a workaround I changed my wrapper to pass only defined options, but would have expected isInt to handle this case.
I noticed that hasOwnProperty is used to check for options in other validators as well if no default option exists. So if addressed this issue would span over multiple validators.
Examples
Additional context
Validator.js version: 13.1.17
The text was updated successfully, but these errors were encountered: