diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 8df88dfd85..2762195775 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace JS { @@ -850,8 +851,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::normalize) if (!form.is_one_of("NFC"sv, "NFD"sv, "NFKC"sv, "NFKD"sv)) return vm.throw_completion(ErrorType::InvalidNormalizationForm, form); - // FIXME: 6. Let ns be the String value that is the result of normalizing S into the normalization form named by f as specified in https://unicode.org/reports/tr15/. - auto ns = string; + // 6. Let ns be the String value that is the result of normalizing S into the normalization form named by f as specified in https://unicode.org/reports/tr15/. + auto unicode_form = Unicode::normalization_form_from_string(form); + auto ns = Unicode::normalize(string, unicode_form); // 7. return ns. return js_string(vm, move(ns)); diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.normalize.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.normalize.js index 3081cf73af..3920302251 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.normalize.js +++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.normalize.js @@ -36,8 +36,7 @@ test("Invalid object throws", () => { ); }); -// Tests below here are skipped due to the function being a stub at the moment -test.skip("Normalization works", () => { +test("Normalization works", () => { var s = "\u1E9B\u0323"; expect(s.normalize("NFC")).toBe("\u1E9B\u0323"); @@ -46,7 +45,7 @@ test.skip("Normalization works", () => { expect(s.normalize("NFKD")).toBe("\u0073\u0323\u0307"); }); -test.skip("Default parameter is NFC", () => { +test("Default parameter is NFC", () => { var s = "\u1E9B\u0323"; expect(s.normalize("NFC")).toBe(s.normalize());