From e08911c3f37a108c0c9defbc2b0665777b85df25 Mon Sep 17 00:00:00 2001 From: Kishan Soni Date: Wed, 23 Oct 2024 11:47:07 +1000 Subject: [PATCH] Disallow mismatching length for isDate --- src/lib/isDate.js | 1 + test/validators.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib/isDate.js b/src/lib/isDate.js index ede3e33e6..3a1e4afd2 100644 --- a/src/lib/isDate.js +++ b/src/lib/isDate.js @@ -28,6 +28,7 @@ export default function isDate(input, options) { options = merge(options, default_date_options); } if (typeof input === 'string' && isValidFormat(options.format)) { + if (options.strictMode && input.length !== options.format.length) return false; const formatDelimiter = options.delimiters .find(delimiter => options.format.indexOf(delimiter) !== -1); const dateDelimiter = options.strictMode diff --git a/test/validators.test.js b/test/validators.test.js index 4df91395c..84f81415c 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -13998,6 +13998,7 @@ describe('Validators', () => { new Date([2014, 2, 15]), new Date('2014-03-15'), '29.02.2020', + '02.29.2020.20', '2024-', '2024-05', '2024-05-',