Repository navigation
Conversation
isValidDate built the comparison Date from an unpadded year, so
new Date('1-01-13') parsed as 2013-01-01 and every valid date with a
year below 1000 failed the strict check. Pad the year to four digits
before constructing the Date.
Fixes validatorjs#2517.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2965 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2600 +1
Branches 658 658
=========================================
+ Hits 2599 2600 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi! Thanks for maintaining validator.js. I found a small bug in strict
isISO8601and would love your review.Problem (fixes #2517)
isValidDatebuildsnew Date('${year}-${month}-${day}')with the year as captured, e.g.new Date('1-01-13'). V8 parses that as 2013-01-01, so thegetUTCFullYear() === yearcheck always fails for years below 1000:Fix
Pad the year to 4 digits before building the date string (same
slice(-4)style already used for month/day).Tests
Added strict-mode cases for
0001-01-13,0001-01-13T00:00:00.000Z,0004-02-29,0099-12-31(valid) and0001-02-29,0099-02-29(invalid). New tests fail on the old code and pass with the fix.npm test(build + lint + full suite) passes: 323 passing.