Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ui_util: Fix HTML injection bug in replace_emoji_with_text.

Anders Kaseorg191345f9d61f
diff --git a/web/src/ui_util.ts b/web/src/ui_util.ts
index 839d420a4cf..52b2b8520f7 100644
--- a/web/src/ui_util.ts
+++ b/web/src/ui_util.ts
@@ -23,12 +23,16 @@ export function place_caret_at_end(el: HTMLElement): void {
}
export function replace_emoji_with_text($element: JQuery): void {
- $element.find(".emoji").replaceWith(function () {
- if ($(this).is("img")) {
- return $(this).attr("alt") ?? "";
- }
- return $(this).text();
- });
+ $element
+ .find(".emoji")
+ .text(function () {
+ if ($(this).is("img")) {
+ return $(this).attr("alt") ?? "";
+ }
+ return $(this).text();
+ })
+ .contents()
+ .unwrap();
}
export function change_katex_to_raw_latex($element: JQuery): void {
diff --git a/web/tests/notifications.test.js b/web/tests/notifications.test.js
index 598ef88cc79..27c853c411d 100644
--- a/web/tests/notifications.test.js
+++ b/web/tests/notifications.test.js
@@ -341,7 +341,7 @@ test("message_is_notifiable", () => {
});
test("basic_notifications", () => {
- $("<div>").set_find_results(".emoji", {replaceWith() {}});
+ $("<div>").set_find_results(".emoji", {text: () => ({contents: () => ({unwrap() {}})})});
$("<div>").set_find_results("span.katex", {each() {}});
$("<div>").children = () => [];