`isISO8601` misroutes signed ordinal dates
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- backend
Research direction
Start at the isISO8601 and isValidDate entry points, focusing on the ordinal-date regex shown in the issue. Run the supplied Node examples after installing validator@13.15.35, then verify that signed ordinal dates use the ordinal branch, valid examples pass, invalid day-of-year values fail, and unsigned behavior remains correct.
Written by the indexing model from the issue text.
Description
Describe the bug
The ordinal-date branch in isValidDate matches with
const ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
That pattern has no sign prefix, although the main isISO8601 regex accepts a
leading + or - on the year. A signed ordinal date therefore fails this
match and falls through to the calendar branch, where the generic
(\d{4})-?(\d{0,2})-?(\d*) split cuts the three-digit day-of-year into a
two-digit month and a one-digit day.
The result is that day-of-year is never validated for signed ordinal dates, and
some valid ones are rejected outright.
Examples
const validator = require('validator'); // 13.15.35
// Day 145 of 2009 exists, but the split reads month 14, day 5 and rejects it
validator.isISO8601('+2009-145', { strict: true }); // false, expected true
// Day 130 exists too; here the split reads month 13, day 0, the guard falls
// through, and it is accepted without any check
validator.isISO8601('+2009-130', { strict: true }); // true, unvalidated
// Unsigned ordinals take the intended branch and behave correctly
validator.isISO8601('2009-145', { strict: true }); // true
Reproductions
The Examples block above runs as-is on Node after
npm install validator@13.15.35; no harness or scaffolding needed.
Additional context
Adding [+-]? to the ordinal pattern would route these to the branch that
already handles them, including the leap-year bound on line 19.
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 76/100
validatorjs/validator.js#2859 ·
-
🐛 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 ·