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

isBefore returns null if first argument is not a valid date #435

Closed
rustybailey opened this issue Sep 17, 2015 · 1 comment
Closed

isBefore returns null if first argument is not a valid date #435

rustybailey opened this issue Sep 17, 2015 · 1 comment

Comments

@rustybailey
Copy link
Contributor

In the isBefore() method, before it does the comparison, it converts both arguments to a date using the toDate() helper. If the argument passed into toDate() is not a valid date, it returns null. However, this means that when we get to the comparison line (https://github.com/chriso/validator.js/blob/master/validator.js#L483), if the original variable is null, that line evaluates to null.

Is this the intended functionality? Shouldn't all validation functions return a boolean? If so, shouldn't we convert those toDate() variables to booleans so that the line would be something like return !!original && !!comparison && original < comparison;?

If this is actually a bug, just let me know and I can open a PR. If it is not a bug, I can find a way to work around it.

@chriso
Copy link
Collaborator

chriso commented Sep 18, 2015

Yeah I'd say that's a bug and return !!original && !!comparison && original < comparison would be a reasonable fix.

@chriso chriso closed this as completed in 04d8b45 Sep 18, 2015
chriso added a commit that referenced this issue Sep 18, 2015
Fix #435: Convert returned comparison in isBefore() to a boolean.
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

2 participants