diff --git a/app/assets/javascripts/discourse/app/lib/text.js b/app/assets/javascripts/discourse/app/lib/text.js index 623e1652461..f87aca89a40 100644 --- a/app/assets/javascripts/discourse/app/lib/text.js +++ b/app/assets/javascripts/discourse/app/lib/text.js @@ -157,7 +157,6 @@ export function excerpt(cooked, length) { resultLength += element.textContent.length; } } else if (element.tagName === "A") { - element.innerHTML = element.innerText; result += element.outerHTML; resultLength += element.innerText.length; } else if (element.tagName === "IMG") { diff --git a/app/assets/javascripts/discourse/tests/unit/lib/text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/text-test.js index 699effbe537..b78b2de6890 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/text-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/text-test.js @@ -1,5 +1,5 @@ import { module, test } from "qunit"; -import { parseAsync } from "discourse/lib/text"; +import { cookAsync, excerpt, parseAsync } from "discourse/lib/text"; module("Unit | Utility | text", function () { test("parseAsync", async function (assert) { @@ -11,4 +11,27 @@ module("Unit | Utility | text", function () { ); }); }); + + test("excerpt", async function (assert) { + let cooked = await cookAsync("Hello! :wave:"); + assert.strictEqual( + await excerpt(cooked, 300), + 'Hello! :wave:' + ); + + cooked = await cookAsync("[:wave:](https://example.com)"); + assert.strictEqual( + await excerpt(cooked, 300), + ':wave:' + ); + + cooked = await cookAsync(''); + assert.strictEqual(await excerpt(cooked, 300), ""); + + cooked = await cookAsync("[``]()"); + assert.strictEqual( + await excerpt(cooked, 300), + "<script>alert('hi')</script>" + ); + }); });