rendered_markdown: Fix HTML injection bug in update_elements.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-04-02 17:50:42 -07:00
committed by Tim Abbott
parent e1029b59ed
commit 4dc27216f4
2 changed files with 10 additions and 5 deletions

View File

@@ -323,9 +323,13 @@ export const update_elements = ($content: JQuery): void => {
// Display emoji (including realm emoji) as text if
// user_settings.emojiset is 'text'.
if (user_settings.emojiset === "text") {
$content.find(".emoji").replaceWith(function (): string {
$content
.find(".emoji")
.text(function () {
const text = $(this).attr("title");
return ":" + text + ":";
});
})
.contents()
.unwrap();
}
};

View File

@@ -467,10 +467,11 @@ run_test("emoji", () => {
const $emoji = $.create("emoji-stub");
$emoji.attr("title", "tada");
let called = false;
$emoji.replaceWith = (f) => {
$emoji.text = (f) => {
const text = f.call($emoji);
assert.equal(":tada:", text);
called = true;
return {contents: () => ({unwrap() {}})};
};
$content.set_find_results(".emoji", $emoji);
user_settings.emojiset = "text";