Browse Source

fix(html-parser): sanitize unclosed tags in markdown rendering (#14309)

Chuckie Li 1 month ago
parent
commit
d5711589cd
1 changed files with 5 additions and 0 deletions
  1. 5 0
      web/app/components/base/markdown.tsx

+ 5 - 0
web/app/components/base/markdown.tsx

@@ -258,6 +258,11 @@ export function Markdown(props: { content: string; className?: string }) {
                 if (node.type === 'element' && node.properties?.ref)
                   delete node.properties.ref
 
+                if (node.type === 'element' && !/^[a-z][a-z0-9]*$/i.test(node.tagName)) {
+                  node.type = 'text'
+                  node.value = `<${node.tagName}`
+                }
+
                 if (node.children)
                   node.children.forEach(iterate)
               }