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

isNull is misleading #574

Closed
trodrigues opened this issue Aug 26, 2016 · 4 comments
Closed

isNull is misleading #574

trodrigues opened this issue Aug 26, 2016 · 4 comments

Comments

@trodrigues
Copy link

trodrigues commented Aug 26, 2016

I was updating a codebase that was using an older version of this library, and started getting these errors on code that was using isNull:

This library (validator.js) validates strings only in...

I then looked at the implementation which simply asserts if the input is a string and then checks the length.

Ideally I think this method should be renamed entirely (to something like isLengthZero) or change the implementation to actually check for null.

I also found this old issue which states the input is coerced before it gets there, but that doesn't seem to be the case. With that in mind, would it make sense for now to submit a PR to actually call toString before?

@ItsMrAkhil
Copy link

I am facing the same error. It is not working if the argument is other than string.

@chriso
Copy link
Collaborator

chriso commented Sep 1, 2016

String coercion was removed from the library and it now validates and sanitizes strings only. Passing any other type of input is an error; it's up to the user to make sure the input is a string. As to why it no longer coerces input, have a look at #486 or a57f3c8; there are too many edge cases that are outside the scope of this library.

I agree that the isNull name is confusing. The name is leftover from earlier versions of the library. I've made a note on this wiki page about changing the name as part of the v6 major bump.

@chriso chriso closed this as completed Sep 1, 2016
chriso added a commit that referenced this issue Sep 27, 2016
lumaxis added a commit to lumaxis/validator that referenced this issue Jun 13, 2017
- Remove isDate()
- Renamed isNull() to isEmpty() (validatorjs/validator.js#574)
lumaxis added a commit to lumaxis/validator that referenced this issue Jun 13, 2017
- Remove isDate()
- Renamed isNull() to isEmpty() (validatorjs/validator.js#574)
@ryannealmes
Copy link

Have you guys removed the functionality for isNull completely from this library?

e.g. validator.isEmpty(null) throws an exception now, so if I wanted to validate if something is empty I would have to do validator.isEmpty(test || "") if I wanted to cater for nulls as well. Is this intentional or am I missing something?

Thanks.

@melroy89
Copy link

melroy89 commented Oct 26, 2019

I still think isNull is now missing. How to validate isNull. I want to check (using express-validator) your isInt() in combination with isNull() (isNull doesn't exists yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants