fix(isDate): fix thrown error on certain invalid cases #2443
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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