1
0
Fork 0

Fix bug when text nodes contain HTML <>

Text nodes don't escape them
This commit is contained in:
Lim Chee Aun 2022-12-17 17:24:26 +08:00
parent b9c762cf53
commit d0579a57d6

View file

@ -20,7 +20,7 @@ function enhanceContent(content, opts = {}) {
// Convert :shortcode: to <img />
let textNodes = extractTextNodes(dom);
textNodes.forEach((node) => {
let html = node.nodeValue;
let html = node.nodeValue.replace(/</g, '&lt;').replace(/>/g, '&gt;');
if (emojis) {
html = emojifyText(html, emojis);
}
@ -34,7 +34,7 @@ function enhanceContent(content, opts = {}) {
// Convert `code` to <code>code</code>
textNodes = extractTextNodes(dom);
textNodes.forEach((node) => {
let html = node.nodeValue;
let html = node.nodeValue.replace(/</g, '&lt;').replace(/>/g, '&gt;');
if (/`[^`]+`/g.test(html)) {
html = html.replaceAll(/(`[^]+?`)/g, '<code>$1</code>');
}