Skip to content
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

Undefined min, max, gt, lt values taken into consideration during validation #2328

Closed
jrtitus opened this issue Oct 20, 2023 · 2 comments
Closed
Labels

Comments

@jrtitus
Copy link

jrtitus commented Oct 20, 2023

Describe the bug
Properties of an object are considered undefined unless set, but an explicit undefined value is taken into consideration when determining if isInt or isFloat succeeds due to the use of hasOwnProperty.

let minCheckPassed = (!options.hasOwnProperty('min') || str >= options.min);
let maxCheckPassed = (!options.hasOwnProperty('max') || str <= options.max);
let ltCheckPassed = (!options.hasOwnProperty('lt') || str < options.lt);
let gtCheckPassed = (!options.hasOwnProperty('gt') || str > options.gt);

Examples

import { isInt } from 'validator'

isInt("5") // => true
isInt("5", {min: 0, max: 10}) // => true
isInt("5", { }} // => true
isInt("5", {min: undefined, max: undefined}) // => false

Maybe it's just my opinion, but I think that last one should also return true.

Additional context
Validator.js version: [email protected]
Node.js version: Node 18.17.1
OS platform: linux

@dk172923
Copy link

Can you assign it to me?

@pano9000
Copy link
Contributor

pano9000 commented Sep 5, 2024

closed by #2416

@pano9000 pano9000 closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants