Pārlūkot izejas kodu

LibWeb: Don't crash on Element.setAttribute() with emoji in name

We were mistakenly using StringBuilder's append(char) when we really
wanted append_code_point(u32).
Andreas Kling 1 gadu atpakaļ
vecāks
revīzija
1b81e0081d

+ 1 - 0
Tests/LibWeb/Text/expected/DOM/setAttribute-with-emoji-in-attribute-name.txt

@@ -0,0 +1 @@
+PASS (Didn't crash)

+ 8 - 0
Tests/LibWeb/Text/input/DOM/setAttribute-with-emoji-in-attribute-name.html

@@ -0,0 +1,8 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const e = document.createElement("div");
+        e.setAttribute("🧐", "");
+        println("PASS (Didn't crash)");
+    });
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/Infra/Strings.cpp

@@ -99,7 +99,7 @@ ErrorOr<String> to_ascii_lowercase(StringView string)
     auto utf8_view = Utf8View { string };
     for (u32 code_point : utf8_view) {
         code_point = AK::to_ascii_lowercase(code_point);
-        TRY(string_builder.try_append(code_point));
+        string_builder.append_code_point(code_point);
     }
     return string_builder.to_string();
 }