fix(isISO8601): pad year to 4 digits in strict validation for years < 1000#2724
Closed
xxiaoxiong wants to merge 1 commit into
Closed
Conversation
… 1000 When `isISO8601` is called with `strict: true`, the `isValidDate` function extracts the year via `Number()`, which converts leading-zero years like `0001` to `1`. The year is then interpolated directly into the date string passed to `new Date()`, causing ambiguous parsing (e.g. `1-01-13` is interpreted as January 13th 2001 instead of January 13th 0001). This fix pads the year to 4 digits before constructing the date string, preserving correct parsing for all year values. Fixes #2517
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2724 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2587 2588 +1
Branches 656 656
=========================================
+ Hits 2587 2588 +1 ☔ View full report in Codecov by Sentry. 🚀 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.
Description
When
isISO8601is called withstrict: true, theisValidDatefunction extracts the year viaNumber(), which converts leading-zero years like0001to1. The year is then interpolated directly into the date string passed tonew Date().For example,
1-01-13is interpreted by JavaScript as January 13th 2001 instead of January 13th 0001, causing thegetUTCFullYear()comparison to fail.Changes
padStart(4, '0')before constructing the date stringRelated Issue
Fixes #2517