Skip to content

Commit eed4839

Browse files
committed
Bug 1783731 - Don't parse single digit mon or mday as an ISO date r=arai
Differential Revision: https://phabricator.services.mozilla.com/D192671
1 parent babdd65 commit eed4839

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

js/src/jsdate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,8 @@ static int DaysInMonth(int year, int month) {
929929
* where:
930930
*
931931
* YYYY = four-digit year or six digit year as +YYYYYY or -YYYYYY
932-
* MM = one or two-digit month (01=January, etc.)
933-
* DD = one or two-digit day of month (01 through 31)
932+
* MM = two-digit month (01=January, etc.)
933+
* DD = two-digit day of month (01 through 31)
934934
* hh = one or two digits of hour (00 through 23) (am/pm NOT allowed)
935935
* mm = one or two digits of minute (00 through 59)
936936
* ss = one or two digits of second (00 through 59)
@@ -1014,9 +1014,9 @@ static bool ParseISOStyleDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
10141014
NEED_NDIGITS(4, year);
10151015
}
10161016
DONE_DATE_UNLESS('-');
1017-
NEED_NDIGITS_OR_LESS(2, month);
1017+
NEED_NDIGITS(2, month);
10181018
DONE_DATE_UNLESS('-');
1019-
NEED_NDIGITS_OR_LESS(2, day);
1019+
NEED_NDIGITS(2, day);
10201020

10211021
done_date:
10221022
if (PEEK('T')) {

js/src/tests/non262/Date/non-iso.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ assertEq(new Date("1997-03-08 1:1:1").getTime(),
4040
new Date("1997-03-08T01:01:01").getTime());
4141
assertEq(new Date("1997-03-08 11").getTime(),
4242
new Date("1997-03-08T11").getTime()); // Date(NaN)
43-
assertEq(new Date("1997-03-08").getTime(),
44-
new Date("1997-03-08").getTime());
45-
assertEq(new Date("1997-03-8").getTime(),
46-
new Date("1997-03-08").getTime());
47-
assertEq(new Date("1997-3-8").getTime(),
48-
new Date("1997-03-08").getTime());
4943
assertEq(new Date("1997-03-08 11:19:10-07").getTime(),
5044
new Date("1997-03-08 11:19:10-0700").getTime());
5145
assertEq(new Date("1997-03-08T11:19:10-07").getTime(),

js/src/tests/non262/Date/parse-dashed-numeric-date.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ inTimeZone("MST", () => {
2121
"19999-09-12 (comment) 23:00:00": new Date(19999, Month.September, 12, 23),
2222
"19999-09-12 22:00:00 GMT-0800": new Date(19999, Month.September, 12, 23),
2323

24+
// Single digit mon or mday
25+
"2021-09-1": new Date(2021, Month.September, 1),
26+
"2021-9-01": new Date(2021, Month.September, 1),
27+
"2021-9-1": new Date(2021, Month.September, 1),
28+
2429
// 1-12 for first number should be month
2530
"1-09-12": new Date(2012, Month.January, 9),
2631
"1-09-2012": new Date(2012, Month.January, 9),

0 commit comments

Comments
 (0)