From 392f5bfebd0cd87de4264fb78efd1156e765a400 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 12 Jan 2022 20:15:43 +0100 Subject: [PATCH] LibJS: Fix fraction substring range in parse_temporal_time_zone_string() Two issues: - The intended range was 9 characters starting from index 1. Since the second argument to String::substring() is the length, 10 is potentially reading further than the string's length (when only providing one fraction digit), causing an assertion failure crash. - The spec's intention to skip the decimal separator by starting at index 1 is incorrect, no decimal separator is present in the result of parsing TimeZoneUTCOffsetFractionalPart. I filed a spec fix for this, see: https://github.com/tc39/proposal-temporal/pull/1999 --- .../LibJS/Runtime/Temporal/AbstractOperations.cpp | 4 +++- .../Tests/builtins/Temporal/TimeZone/TimeZone.from.js | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index b8aabf494cb..b24bc03a15b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1663,7 +1663,9 @@ ThrowCompletionOr parse_temporal_time_zone_string(GlobalObject auto fraction = String::formatted("{}000000000", *fraction_part); // ii. Let nanoseconds be the String value equal to the substring of fraction from 1 to 10. // iii. Set nanoseconds to ! ToIntegerOrInfinity(nanoseconds). - nanoseconds = *fraction.substring(1, 10).to_int(); + // FIXME: 1-10 is wrong and should be 0-9; the decimal separator is no longer present in the parsed string. + // See: https://github.com/tc39/proposal-temporal/pull/1999 + nanoseconds = *fraction.substring(0, 9).to_int(); } // h. Else, else { diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.from.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.from.js index 04b85097f66..8ae6222b95b 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.from.js @@ -30,14 +30,12 @@ describe("normal behavior", () => { ["1970-01-01T00:00:00.000000000+01:00:00", "+01:00"], ["1970-01-01+12:34", "+12:34"], ["1970-01-01+12:34:56", "+12:34:56"], - // FIXME: These currently crash :^( - // ["1970-01-01+12:34:56.789", "+12:34:56.789"], - // ["1970-01-01+12:34:56.789[-01:00]", "+12:34:56.789"], + ["1970-01-01+12:34:56.789", "+12:34:56.789"], + ["1970-01-01+12:34:56.789[-01:00]", "+12:34:56.789"], ["1970-01-01-12:34", "-12:34"], ["1970-01-01-12:34:56", "-12:34:56"], - // FIXME: These currently crash :^( - // ["1970-01-01-12:34:56.789", "-12:34:56.789"], - // ["1970-01-01-12:34:56.789[+01:00]", "-12:34:56.789"], + ["1970-01-01-12:34:56.789", "-12:34:56.789"], + ["1970-01-01-12:34:56.789[+01:00]", "-12:34:56.789"], ]; for (const [arg, expected] of values) { expect(Temporal.TimeZone.from(arg).id).toBe(expected);