mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-05 01:10:24 +00:00
LibJS: Remove unnecessary Temporal month code check
This is an editorial change in the Temporal proposal. See: https://github.com/tc39/proposal-temporal/commit/9110854 This change actually exposed a bug in our validator for month codes (which is only used by this same function). We would previously allow "M00" as a month code, which is invalid (it must be "M00L").
This commit is contained in:
Notes:
github-actions[bot]
2025-11-12 21:21:08 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/041c4f4c797 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6802
@@ -145,13 +145,15 @@ Vector<String> const& available_calendars()
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-temporal/#prod-MonthCode
|
||||
static bool is_valid_month_code_string(StringView month_code)
|
||||
static constexpr bool is_valid_month_code_string(StringView month_code)
|
||||
{
|
||||
// MonthCode :::
|
||||
// M00L
|
||||
// M0 NonZeroDigit L[opt]
|
||||
// M NonZeroDigit DecimalDigit L[opt]
|
||||
if (month_code.length() != 3 && month_code.length() != 4)
|
||||
auto length = month_code.length();
|
||||
|
||||
if (length != 3 && length != 4)
|
||||
return false;
|
||||
|
||||
if (month_code[0] != 'M')
|
||||
@@ -160,7 +162,9 @@ static bool is_valid_month_code_string(StringView month_code)
|
||||
if (!is_ascii_digit(month_code[1]) || !is_ascii_digit(month_code[2]))
|
||||
return false;
|
||||
|
||||
if (month_code.length() == 4 && month_code[3] != 'L')
|
||||
if (length == 3 && month_code[1] == '0' && month_code[2] == '0')
|
||||
return false;
|
||||
if (length == 4 && month_code[3] != 'L')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -204,11 +208,7 @@ ThrowCompletionOr<MonthCode> parse_month_code(VM& vm, StringView month_code)
|
||||
// 7. Let monthNumber be ℝ(StringToNumber(monthCodeDigits)).
|
||||
auto month_number = month_code_digits.to_number<u8>().value();
|
||||
|
||||
// 8. If monthNumber is 0 and isLeapMonth is false, throw a RangeError exception.
|
||||
if (month_number == 0 && !is_leap_month)
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidMonthCode);
|
||||
|
||||
// 9. Return the Record { [[MonthNumber]]: monthNumber, [[IsLeapMonth]]: isLeapMonth }.
|
||||
// 8. Return the Record { [[MonthNumber]]: monthNumber, [[IsLeapMonth]]: isLeapMonth }.
|
||||
return MonthCode { month_number, is_leap_month };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user