Skip to content

Small fixes in Date.parse #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47763,7 +47763,9 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
if (!string_get_digits(sp, &p, &fields[5], 1, 2))
return FALSE;
string_get_milliseconds(sp, &p, &fields[6]);
}
} else
if (sp[p] != '\0' && sp[p] != ' ')
return FALSE;
has_time = TRUE;
} else {
if (p - p_start > 2) {
Expand All @@ -47785,11 +47787,17 @@ static BOOL js_date_parse_otherstring(const uint8_t *sp,
string_skip_until(sp, &p, "0123456789 -/(");
} else
if (has_time && string_match(sp, &p, "PM")) {
if (fields[3] < 12)
/* hours greater than 12 will be incremented and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also have a range check?

Suggested change
if (fields[3] != 12)
if (fields[3] > 12)
return FALSE;
if (fields[3] != 12)

It looks like it'd accept e.g. 13:00 PM now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fields[3] != 12 suffices to reject hours larger than 12 because they will be incremented and exceed 24, thus be caught by the range check in js_Date_parse().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shall add an explanatory comment for clarity

rejected by the range check in js_Date_parse */
/* 00:00 PM will be silently converted as 12:00 */
if (fields[3] != 12)
fields[3] += 12;
continue;
} else
if (has_time && string_match(sp, &p, "AM")) {
/* 00:00 AM will be silently accepted */
if (fields[3] > 12)
return FALSE;
if (fields[3] == 12)
fields[3] -= 12;
continue;
Expand Down
1 change: 0 additions & 1 deletion v8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ Failure (54[]): expected <true> found <false>
Failure (55[]): expected <true> found <false>
Failure (56[]): expected <true> found <false>
=== date-parse.js
Failure (May 25 2008 1:30( )AM (PM) is not NaN.): expected <true> found <false>
=== declare-locally.js
=== deep-recursion.js
=== define-property-gc.js
Expand Down