From 4cf7de64f3f0324b1f4d92969f82f77c9a8885db Mon Sep 17 00:00:00 2001 From: yfwmaniish Date: Tue, 1 Sep 2026 10:25:58 +0530 Subject: [PATCH] fix(isISO8601): route signed ordinal dates to the day-of-year check isValidDate()'s ordinal-date branch matched /^(\d{4})-?(\d{3}).../, with no sign prefix, even though the top-level iso8601 regex accepts a leading +/- on the year. A signed ordinal date like "+2009-145" therefore fell through to the generic calendar-date split (\d{4})-?(\d{0,2})-?(\d*), which cuts the 3-digit day-of-year into a 2-digit "month" and 1-digit "day" -- misvalidating or, when the split leaves day as "0" (falsy), skipping validation entirely and returning true unconditionally. Add [+-]? to the ordinal pattern so signed ordinal dates route to the branch that already has the correct leap-year-aware day-of-year check. Fixes #2860 --- src/lib/isISO8601.js | 2 +- test/validators.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/isISO8601.js b/src/lib/isISO8601.js index 6eea9ae27..d8809a671 100644 --- a/src/lib/isISO8601.js +++ b/src/lib/isISO8601.js @@ -11,7 +11,7 @@ const isValidDate = (str) => { // this check is meant to catch invalid dates // like 2009-02-31 // first check for ordinal dates - const ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/); + const ordinalMatch = str.match(/^[\+-]?(\d{4})-?(\d{3})([ T]{1}\.*|$)/); if (ordinalMatch) { const oYear = Number(ordinalMatch[1]); const oDay = Number(ordinalMatch[2]); diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..61003c5bd 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12443,6 +12443,9 @@ describe('Validators', () => { '2009-222', '2020-366', '2400-366', + '+2009-145', + '+2009-130', + '-2009-145', ], invalid: [ '2010-02-30',