`isISO8601` strict mode never validates week dates
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- backend
Research direction
Start by running the provided Node reproductions, then inspect the isValidDate strict-mode path around the month/day extraction and line 31. Done means strict mode rejects nonexistent week dates such as 2019-W53-1 and 2021-W53-1 while accepting valid 53-week dates such as 2015-W53-1 and 2020-W53-1.
Written by the indexing model from the issue text.
Description
Describe the bug
With strict: true, isValidDate extracts month and day with
const match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
For a week date such as 2021-W53-1 the W is not a digit, so (\d{0,2}) and
(\d*) both match the empty string. Number('') is 0, so the
if (month && day) guard at line 31 is false and the function returns true
without performing any check.
The effect is that strict: true never validates a week date at all. The
53rd week is accepted in years that only have 52 ISO weeks, and no week date
can ever be rejected by strict mode.
Examples
const validator = require('validator'); // 13.15.35
// 2019 and 2021 have 52 ISO weeks, so W53 does not exist in either
validator.isISO8601('2019-W53-1', { strict: true }); // true, expected false
validator.isISO8601('2021-W53-1', { strict: true }); // true, expected false
// 2015 and 2020 genuinely have 53 ISO weeks, so these are correct by accident
validator.isISO8601('2015-W53-1', { strict: true }); // true
validator.isISO8601('2020-W53-1', { strict: true }); // true
Every one of those returns true through the same fall-through path, so the
two correct answers are not evidence of a working check.
Reproductions
The Examples block above runs as-is on Node after
npm install validator@13.15.35; no harness or scaffolding needed.
Additional context
Related to the rewrite proposed in #2564, but reported separately because the
underlying behavior is that strict mode silently skips week dates rather than
mis-validating them.
Validator.js version: 13.15.35
Node.js version: v26.7.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 86/100
validatorjs/validator.js#2858 ·
All issues in validatorjs/validator.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
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 ·
-
client-controller-update ta-bot-triage team-money-movement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-mobile#36594 ·