From 1b81e0081db52fb743a3de93ab7286b4a8c3ca6b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Dec 2023 23:20:33 +0100 Subject: [PATCH] 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). --- .../DOM/setAttribute-with-emoji-in-attribute-name.txt | 1 + .../DOM/setAttribute-with-emoji-in-attribute-name.html | 8 ++++++++ Userland/Libraries/LibWeb/Infra/Strings.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/DOM/setAttribute-with-emoji-in-attribute-name.txt create mode 100644 Tests/LibWeb/Text/input/DOM/setAttribute-with-emoji-in-attribute-name.html diff --git a/Tests/LibWeb/Text/expected/DOM/setAttribute-with-emoji-in-attribute-name.txt b/Tests/LibWeb/Text/expected/DOM/setAttribute-with-emoji-in-attribute-name.txt new file mode 100644 index 0000000000..35c957db0f --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/setAttribute-with-emoji-in-attribute-name.txt @@ -0,0 +1 @@ +PASS (Didn't crash) diff --git a/Tests/LibWeb/Text/input/DOM/setAttribute-with-emoji-in-attribute-name.html b/Tests/LibWeb/Text/input/DOM/setAttribute-with-emoji-in-attribute-name.html new file mode 100644 index 0000000000..f9b3977941 --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/setAttribute-with-emoji-in-attribute-name.html @@ -0,0 +1,8 @@ + + diff --git a/Userland/Libraries/LibWeb/Infra/Strings.cpp b/Userland/Libraries/LibWeb/Infra/Strings.cpp index c37d70d4cb..c4321850b8 100644 --- a/Userland/Libraries/LibWeb/Infra/Strings.cpp +++ b/Userland/Libraries/LibWeb/Infra/Strings.cpp @@ -99,7 +99,7 @@ ErrorOr 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(); }