You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When giving a valid date with year before 1000, the isISO8601 validator is returning false when strict option is set to true.
The issue in the isValidDate function of the src/lib/isISO8601.js file.
At line 30, a new Date object is instanced using a string built with year, monthString and dayString.
But contrary to month and day, no leading zeros are added to year. This is causing the object Date to not parse correctly the date and in resulting in the d.getUTCFullYear() === year test to fail.
Examples
Using the valid date 0001-01-13T00:00:00.000Z, the parsed year variable will be equal to 1, month to 1 and day to 13.
The Date object will be constructed using the following string: 1-01-13.
This is interpreted as January 1st 2013 instead of January 13th 0001 which obviously lead to the d.getUTCFullYear() === year test to fail (2013 is different than 1)
Additional context
Validator.js version: v13.12.0
Node.js version: v22.12.0
OS platform: linux
The text was updated successfully, but these errors were encountered:
Describe the bug
When giving a valid date with year before 1000, the
isISO8601
validator is returningfalse
whenstrict
option is set totrue
.The issue in the
isValidDate
function of thesrc/lib/isISO8601.js
file.At line 30, a new
Date
object is instanced using a string built withyear
,monthString
anddayString
.But contrary to
month
andday
, no leading zeros are added toyear
. This is causing the object Date to not parse correctly the date and in resulting in thed.getUTCFullYear() === year
test to fail.Examples
Using the valid date
0001-01-13T00:00:00.000Z
, the parsedyear
variable will be equal to1
,month
to1
andday
to13
.The Date object will be constructed using the following string:
1-01-13
.This is interpreted as January 1st 2013 instead of January 13th 0001 which obviously lead to the
d.getUTCFullYear() === year
test to fail (2013 is different than 1)Additional context
Validator.js version: v13.12.0
Node.js version: v22.12.0
OS platform: linux
The text was updated successfully, but these errors were encountered: