diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp index 5fb2c5b2c3..1b591e24ec 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNames.cpp @@ -150,8 +150,12 @@ ThrowCompletionOr canonical_code_for_display_names(GlobalObject& global_o if (!Unicode::is_type_identifier(code)) return vm.throw_completion(global_object, ErrorType::OptionIsNotValidValue, code, "calendar"sv); - // b. Let code be the result of mapping code to lower case as described in 6.1. - // c. Return code. + // b. If code uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 LDML ยง 3.3 BCP 47 Conformance, throw a RangeError exception. + if (code.contains('_')) + return vm.throw_completion(global_object, ErrorType::OptionIsNotValidValue, code, "calendar"sv); + + // c. Let code be the result of mapping code to lower case as described in 6.1. + // d. Return code. return js_string(vm, code.to_lowercase_string()); } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DisplayNames/DisplayNames.prototype.of.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DisplayNames/DisplayNames.prototype.of.js index 4b90da3e1e..1d83add971 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DisplayNames/DisplayNames.prototype.of.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DisplayNames/DisplayNames.prototype.of.js @@ -27,6 +27,10 @@ describe("errors", () => { expect(() => { new Intl.DisplayNames("en", { type: "calendar" }).of("hello!"); }).toThrowWithMessage(RangeError, "hello! is not a valid value for option calendar"); + + expect(() => { + new Intl.DisplayNames("en", { type: "calendar" }).of("abc_def"); + }).toThrowWithMessage(RangeError, "abc_def is not a valid value for option calendar"); }); test("invalid dateTimeField", () => {