Bug 1783731 - Don't parse single digit mon or mday as an ISO date r=arai

Differential Revision: https://phabricator.services.mozilla.com/D192671
This commit is contained in:
Vinny Diehl 2023-11-04 02:05:10 +00:00
parent babdd651fe
commit eed4839cc0
3 changed files with 9 additions and 10 deletions

View File

@ -929,8 +929,8 @@ static int DaysInMonth(int year, int month) {
* where:
*
* YYYY = four-digit year or six digit year as +YYYYYY or -YYYYYY
* MM = one or two-digit month (01=January, etc.)
* DD = one or two-digit day of month (01 through 31)
* MM = two-digit month (01=January, etc.)
* DD = two-digit day of month (01 through 31)
* hh = one or two digits of hour (00 through 23) (am/pm NOT allowed)
* mm = one or two digits of minute (00 through 59)
* ss = one or two digits of second (00 through 59)
@ -1014,9 +1014,9 @@ static bool ParseISOStyleDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
NEED_NDIGITS(4, year);
}
DONE_DATE_UNLESS('-');
NEED_NDIGITS_OR_LESS(2, month);
NEED_NDIGITS(2, month);
DONE_DATE_UNLESS('-');
NEED_NDIGITS_OR_LESS(2, day);
NEED_NDIGITS(2, day);
done_date:
if (PEEK('T')) {

View File

@ -40,12 +40,6 @@ assertEq(new Date("1997-03-08 1:1:1").getTime(),
new Date("1997-03-08T01:01:01").getTime());
assertEq(new Date("1997-03-08 11").getTime(),
new Date("1997-03-08T11").getTime()); // Date(NaN)
assertEq(new Date("1997-03-08").getTime(),
new Date("1997-03-08").getTime());
assertEq(new Date("1997-03-8").getTime(),
new Date("1997-03-08").getTime());
assertEq(new Date("1997-3-8").getTime(),
new Date("1997-03-08").getTime());
assertEq(new Date("1997-03-08 11:19:10-07").getTime(),
new Date("1997-03-08 11:19:10-0700").getTime());
assertEq(new Date("1997-03-08T11:19:10-07").getTime(),

View File

@ -21,6 +21,11 @@ inTimeZone("MST", () => {
"19999-09-12 (comment) 23:00:00": new Date(19999, Month.September, 12, 23),
"19999-09-12 22:00:00 GMT-0800": new Date(19999, Month.September, 12, 23),
// Single digit mon or mday
"2021-09-1": new Date(2021, Month.September, 1),
"2021-9-01": new Date(2021, Month.September, 1),
"2021-9-1": new Date(2021, Month.September, 1),
// 1-12 for first number should be month
"1-09-12": new Date(2012, Month.January, 9),
"1-09-2012": new Date(2012, Month.January, 9),