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

fix(isDate): fix thrown error on certain invalid cases #2443

Merged
merged 2 commits into from
Aug 25, 2024

Conversation

pano9000
Copy link
Contributor

Fix for #2427 - isDate will not throw an Error anymore, but correctly return false for these invalid cases.

This is done, by changing the zip function to take the max not the min length -> if there is any discrepancy between input and dateFormat (i.e. input has only 2 parts, but dateFormat has 3), this then causes one of the values inside the zippedArr "tuple" to be undefined, which we then test for.
And if undefined -> we return false.

This avoids us running into the error described in #2427, where it then tried to read the length of "undefined".

As a bonus, this change also fixes some false positives (e.g. "2024-05-05-abc" was returning true, which it shouldn't have).
Generally speaking, the isDate function is in need of a proper refactoring, it kinda feels a bit strange in its current form -> but this is something for the future :-)

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@rubiin rubiin merged commit ff56dcf into validatorjs:master Aug 25, 2024
10 checks passed
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

Successfully merging this pull request may close these issues.

3 participants