From c95ebdf15328e3a3be886d1844c6be437172ccb2 Mon Sep 17 00:00:00 2001 From: abhijeet117 Date: Sun, 23 Aug 2026 23:17:43 +0530 Subject: [PATCH] fix(isISO8601): reject whitespace other than space as date-time separator --- src/lib/isISO8601.js | 2 +- test/validators.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib/isISO8601.js b/src/lib/isISO8601.js index 6eea9ae27..873aec756 100644 --- a/src/lib/isISO8601.js +++ b/src/lib/isISO8601.js @@ -2,7 +2,7 @@ import assertString from './util/assertString'; /* eslint-disable max-len */ // from http://goo.gl/0ejHHW -const iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; +const iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T ]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; // same as above, except with a strict 'T' separator between date and time const iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; /* eslint-enable max-len */ diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..56f623dcb 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12420,6 +12420,22 @@ describe('Validators', () => { }); }); + it('should validate ISO 8601 dates, rejecting whitespace other than a space as the date-time separator', () => { + test({ + validator: 'isISO8601', + valid: [ + '2009-05-19T14:39:22', + '2009-05-19 14:39:22', + ], + invalid: [ + '2009-05-19\t14:39:22', + '2009-05-19\n14:39:22', + '2009-05-19\f14:39:22', + '2009-05-19\v14:39:22', + ], + }); + }); + it('should validate ISO 8601 dates, with strict = true (regression)', () => { test({ validator: 'isISO8601',