From 0620adee3cc63580da1f00744a50846883008cb7 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Wed, 27 Mar 2024 09:28:43 +0100 Subject: [PATCH 1/2] Small fixes in Date.parse - reject AM/PM suffix for hours > 12 - stricter time parser (fixes last v8 test) --- quickjs.c | 8 ++++++-- v8.txt | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/quickjs.c b/quickjs.c index dd1977417..9452dd4fb 100644 --- a/quickjs.c +++ b/quickjs.c @@ -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) { @@ -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) fields[3] += 12; continue; } else if (has_time && string_match(sp, &p, "AM")) { + if (fields[3] > 12) + return FALSE; if (fields[3] == 12) fields[3] -= 12; continue; diff --git a/v8.txt b/v8.txt index 6da607ee0..178ad6ece 100644 --- a/v8.txt +++ b/v8.txt @@ -137,7 +137,6 @@ Failure (54[]): expected found Failure (55[]): expected found Failure (56[]): expected found === date-parse.js -Failure (May 25 2008 1:30( )AM (PM) is not NaN.): expected found === declare-locally.js === deep-recursion.js === define-property-gc.js From 53e256f455821467d194c9918d90687308099e76 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Wed, 27 Mar 2024 11:41:44 +0100 Subject: [PATCH 2/2] add explanatory comments --- quickjs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/quickjs.c b/quickjs.c index 9452dd4fb..86fbfed01 100644 --- a/quickjs.c +++ b/quickjs.c @@ -47787,11 +47787,15 @@ 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")) { + /* hours greater than 12 will be incremented and + 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)