From 8a49a1746e60da951b7e177c8f5d631886df96c5 Mon Sep 17 00:00:00 2001 From: sumit joshi <47482270+Sumit-tech-joshi@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:14:39 -0700 Subject: [PATCH 1/3] Add validation Hyphen before year is not allowed --- src/lib/isDate.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/isDate.js b/src/lib/isDate.js index f0b28917a..dc69b3bc1 100644 --- a/src/lib/isDate.js +++ b/src/lib/isDate.js @@ -22,7 +22,7 @@ function zip(date, format) { } export default function isDate(input, options) { - if (typeof options === 'string') { // Allow backward compatbility for old format isDate(input [, format]) + if (typeof options === 'string') { // Allow backward compatibility for old format isDate(input [, format]) options = merge({ format: options }, default_date_options); } else { options = merge(options, default_date_options); @@ -49,6 +49,11 @@ export default function isDate(input, options) { let fullYear = dateObj.y; + // Check if the year starts with a hyphen + if (fullYear.startsWith('-')) { + return false; // Hyphen before year is not allowed + } + if (dateObj.y.length === 2) { const parsedYear = parseInt(dateObj.y, 10); From 309c958a5a80e3dbaa3a6c7d44119dac46454ac9 Mon Sep 17 00:00:00 2001 From: sumit joshi <47482270+Sumit-tech-joshi@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:33:03 -0700 Subject: [PATCH 2/3] Add invalid test case for is date function --- test/validators.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/validators.test.js b/test/validators.test.js index 6c68cd71a..946e96947 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12957,6 +12957,8 @@ describe('Validators', () => { '2019-02-29', // non-leap year '2020-04-31', // invalid date '2020/03-15', // mixed delimiter + '-2020-04-19', + '-2023/05/24' ], }); test({ From eadfad42794aef21b909132e40c7509b9282c372 Mon Sep 17 00:00:00 2001 From: sumit joshi <47482270+Sumit-tech-joshi@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:38:11 -0700 Subject: [PATCH 3/3] Added missing coma --- test/validators.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.test.js b/test/validators.test.js index 946e96947..2d66e5831 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12958,7 +12958,7 @@ describe('Validators', () => { '2020-04-31', // invalid date '2020/03-15', // mixed delimiter '-2020-04-19', - '-2023/05/24' + '-2023/05/24', ], }); test({