From 917c3c81dfd7924f290e457e84cf7321d7a90042 Mon Sep 17 00:00:00 2001 From: abhijeet117 Date: Mon, 24 Aug 2026 00:45:04 +0530 Subject: [PATCH] fix(isISO8601): validate signed ordinal dates in strict mode --- src/lib/isISO8601.js | 6 +++--- test/validators.test.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib/isISO8601.js b/src/lib/isISO8601.js index 6eea9ae27..a8cfbd29f 100644 --- a/src/lib/isISO8601.js +++ b/src/lib/isISO8601.js @@ -11,10 +11,10 @@ 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]); + const oYear = Number(ordinalMatch[2]); + const oDay = Number(ordinalMatch[3]); // if is leap year if ((oYear % 4 === 0 && oYear % 100 !== 0) || oYear % 400 === 0) return oDay <= 366; return oDay <= 365; diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..ab271e946 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12453,6 +12453,22 @@ describe('Validators', () => { }); }); + it('should validate ISO 8601 dates, validating signed ordinal dates in strict mode', () => { + test({ + validator: 'isISO8601', + args: [ + { strict: true }, + ], + valid: [ + '+2009-145', + '+2020-366', + ], + invalid: [ + '+2009-366', + ], + }); + }); + it('should validate ISO 8601 dates, with strictSeparator = true', () => { test({ validator: 'isISO8601',