From fc31e6e7dccf9af4876bbb0062d0cc0e46f6cb3a Mon Sep 17 00:00:00 2001 From: Kishan Soni Date: Mon, 28 Oct 2024 02:16:43 +1000 Subject: [PATCH] Disallow mismatching length for isDate (#2481) Co-authored-by: Rubin Bhandari --- 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 6b61c18b7..08d76f821 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -14001,6 +14001,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-',