Skip to content

Commit 0836777

Browse files
fix(isDate): hyphen before year is not allowed (#2381)
1 parent eacccaf commit 0836777

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/lib/isDate.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function zip(date, format) {
2222
}
2323

2424
export default function isDate(input, options) {
25-
if (typeof options === 'string') { // Allow backward compatbility for old format isDate(input [, format])
25+
if (typeof options === 'string') { // Allow backward compatibility for old format isDate(input [, format])
2626
options = merge({ format: options }, default_date_options);
2727
} else {
2828
options = merge(options, default_date_options);
@@ -49,6 +49,11 @@ export default function isDate(input, options) {
4949

5050
let fullYear = dateObj.y;
5151

52+
// Check if the year starts with a hyphen
53+
if (fullYear.startsWith('-')) {
54+
return false; // Hyphen before year is not allowed
55+
}
56+
5257
if (dateObj.y.length === 2) {
5358
const parsedYear = parseInt(dateObj.y, 10);
5459

test/validators.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -13087,6 +13087,8 @@ describe('Validators', () => {
1308713087
'2019-02-29', // non-leap year
1308813088
'2020-04-31', // invalid date
1308913089
'2020/03-15', // mixed delimiter
13090+
'-2020-04-19',
13091+
'-2023/05/24',
1309013092
],
1309113093
});
1309213094
test({

0 commit comments

Comments
 (0)