`isISO8601` misroutes signed ordinal dates

Open Beginner friendly
#2,860 0 comments 0 reactions 0 assignees View on GitHub

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

🐛 bug

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from validatorjs/validator.js

All issues in validatorjs/validator.js

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.