From 93d1742fc44b4a4b05c11a1fc0fa9a3f2c307d4c Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Wed, 27 Mar 2024 12:48:08 +0100 Subject: [PATCH] Small fixes in Date.parse (#333) * Small fixes in Date.parse - reject AM/PM suffix for hours > 12 - stricter time parser (fixes last v8 test) - add explanatory comments --- quickjs.c | 12 ++++++++++-- v8.txt | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/quickjs.c b/quickjs.c index 847721d..402f8f0 100644 --- a/quickjs.c +++ b/quickjs.c @@ -47770,7 +47770,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) { @@ -47792,11 +47794,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 + 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; diff --git a/v8.txt b/v8.txt index 6da607e..178ad6e 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