FIX: Correctly render link title in draft preview (#18906)
The additional unescaping could cause link titles to be rendered incorrectly.
This commit is contained in:
parent
7fca07821b
commit
4b3e5133b0
|
@ -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") {
|
||||
|
|
|
@ -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! <img src="/images/emoji/google_classic/wave.png?v=12" title=":wave:" class="emoji" alt=":wave:" loading="lazy" width="20" height="20">'
|
||||
);
|
||||
|
||||
cooked = await cookAsync("[:wave:](https://example.com)");
|
||||
assert.strictEqual(
|
||||
await excerpt(cooked, 300),
|
||||
'<a href="https://example.com"><img src="/images/emoji/google_classic/wave.png?v=12" title=":wave:" class="emoji only-emoji" alt=":wave:" loading="lazy" width="20" height="20"></a>'
|
||||
);
|
||||
|
||||
cooked = await cookAsync('<script>alert("hi")</script>');
|
||||
assert.strictEqual(await excerpt(cooked, 300), "");
|
||||
|
||||
cooked = await cookAsync("[`<script>alert('hi')</script>`]()");
|
||||
assert.strictEqual(
|
||||
await excerpt(cooked, 300),
|
||||
"<a><code><script>alert('hi')</script></code></a>"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue