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.

rendered_markdown: Fix HTML injection bug in update_elements.

Anders Kaseorg4dc27216f4d2
diff --git a/web/src/rendered_markdown.ts b/web/src/rendered_markdown.ts
index ec916dc13ae..10166b809b8 100644
--- a/web/src/rendered_markdown.ts
+++ b/web/src/rendered_markdown.ts
@@ -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 {
- const text = $(this).attr("title");
- return ":" + text + ":";
- });
+ $content
+ .find(".emoji")
+ .text(function () {
+ const text = $(this).attr("title");
+ return ":" + text + ":";
+ })
+ .contents()
+ .unwrap();
}
};
diff --git a/web/tests/rendered_markdown.test.js b/web/tests/rendered_markdown.test.js
index 2003e82ed08..6eb8b559eeb 100644
--- a/web/tests/rendered_markdown.test.js
+++ b/web/tests/rendered_markdown.test.js
@@ -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";