ui_util: Fix HTML injection bug in replace_emoji_with_text.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-04-02 17:51:03 -07:00
committed by Tim Abbott
parent 4dc27216f4
commit 191345f9d6
2 changed files with 11 additions and 7 deletions

View File

@@ -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 {