isISO8601 does not support dates with year inferior to 1000 in strict mode
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- backend
Research direction
Start in src/lib/isISO8601.js and inspect the isValidDate function, especially how the year, monthString, and dayString are used to construct the Date object in strict mode. Verify the behavior with the reported 0001-01-13T00:00:00.000Z example; done means valid years below 1000 pass strict validation without breaking existing ISO 8601 checks.
Written by the indexing model from the issue text.
Description
Describe the bug
When giving a valid date with year before 1000, the isISO8601 validator is returning false when strict option is set to true.
The issue in the isValidDate function of the src/lib/isISO8601.js file.
At line 30, a new Date object is instanced using a string built with year, monthString and dayString.
But contrary to month and day, no leading zeros are added to year. This is causing the object Date to not parse correctly the date and in resulting in the d.getUTCFullYear() === year test to fail.
Examples
Using the valid date 0001-01-13T00:00:00.000Z, the parsed year variable will be equal to 1, month to 1 and day to 13.
The Date object will be constructed using the following string: 1-01-13.
This is interpreted as January 1st 2013 instead of January 13th 0001 which obviously lead to the d.getUTCFullYear() === year test to fail (2013 is different than 1)
Additional context
Validator.js version: v13.12.0
Node.js version: v22.12.0
OS platform: linux
- Dominant language
- JavaScript
- Stars
- 23.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from validatorjs/validator.js
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
validatorjs/validator.js#2885 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
validatorjs/validator.js#2862 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
validatorjs/validator.js#2861 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
validatorjs/validator.js#2860 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
validatorjs/validator.js#2859 ·
All issues in validatorjs/validator.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·