fix(isDate): fix thrown error on certain invalid cases by pano9000 · Pull Request #2443 · validatorjs/validator.js
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)