Skip to content
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

Small fixes in Date.parse #333

Merged
merged 2 commits into from
Mar 27, 2024
Merged

Conversation

chqrlie
Copy link
Collaborator

@chqrlie chqrlie commented Mar 27, 2024

  • reject AM/PM suffix for hours > 12
  • stricter time parser (fixes last v8 test)

- reject AM/PM suffix for hours > 12
- stricter time parser (fixes last v8 test)
@@ -47785,11 +47787,13 @@ 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)
if (fields[3] != 12)
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

@chqrlie chqrlie merged commit 93d1742 into quickjs-ng:master Mar 27, 2024
38 checks passed
@chqrlie chqrlie deleted the date-parse-fix branch March 27, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants