Skip to content

Commit aa1c560

Browse files
committed
fix(desktop): hang on backtracing-prone regex
1 parent 3aca9e5 commit aa1c560

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

packages/ui/src/components/markdown.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ import { useMarked } from "../context/marked"
22
import { ComponentProps, createResource, splitProps } from "solid-js"
33

44
function strip(text: string): string {
5-
const wrappedRe = /^\s*<([A-Za-z]\w*)>\s*([\s\S]*?)\s*<\/\1>\s*$/
6-
const match = text.match(wrappedRe)
7-
return match ? match[2] : text
5+
const trimmed = text.trim()
6+
const match = trimmed.match(/^<([A-Za-z]\w*)>/)
7+
if (!match) return text
8+
9+
const tagName = match[1]
10+
const closingTag = `</${tagName}>`
11+
if (trimmed.endsWith(closingTag)) {
12+
const content = trimmed.slice(match[0].length, -closingTag.length)
13+
return content.trim()
14+
}
15+
16+
return text
817
}
918

1019
export function Markdown(

0 commit comments

Comments
 (0)