From e95f225362644e7c1818aeef650a5ae6ddeb070b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 20 Jul 2025 13:01:39 -0400 Subject: [PATCH] LibJS: Correctly disallow certain calendar-based Temporal strings This is an editorial change in the Temporal proposal. See: https://github.com/tc39/proposal-temporal/commit/d83241f --- .../Runtime/Temporal/AbstractOperations.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index a9336fffab9..d822e16a8d9 100644 --- a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1178,17 +1178,22 @@ ThrowCompletionOr parse_iso_date_time(VM& vm, StringView iso_ } } - // 3. If goal is TemporalMonthDayString or TemporalYearMonthString, calendar is not EMPTY, and the - // ASCII-lowercase of calendar is not "iso8601", throw a RangeError exception. - if (goal == Production::TemporalMonthDayString || goal == Production::TemporalYearMonthString) { + // 3. If goal is TemporalYearMonthString and parseResult does not contain a DateDay Parse Node, then + if (goal == Production::TemporalYearMonthString && !parse_result->date_day.has_value()) { + // a. If calendar is not empty and the ASCII-lowercase of calendar is not "iso8601", throw a RangeError exception. if (calendar.has_value() && !calendar->equals_ignoring_ascii_case("iso8601"sv)) return vm.throw_completion(ErrorType::TemporalInvalidCalendarIdentifier, *calendar); } - // 4. If goal is TemporalMonthDayString and parseResult does not contain a DateYear Parse Node, set - // yearAbsent to true. - if (goal == Production::TemporalMonthDayString && !parse_result->date_year.has_value()) + // 4. If goal is TemporalMonthDayString and parseResult does not contain a DateYear Parse Node, then + if (goal == Production::TemporalMonthDayString && !parse_result->date_year.has_value()) { + // a. If calendar is not empty and the ASCII-lowercase of calendar is not "iso8601", throw a RangeError exception. + if (calendar.has_value() && !calendar->equals_ignoring_ascii_case("iso8601"sv)) + return vm.throw_completion(ErrorType::TemporalInvalidCalendarIdentifier, *calendar); + + // b. Set yearAbsent to true. year_absent = true; + } } }