diff options
| author | Adam <[email protected]> | 2025-12-24 05:49:35 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-12-24 05:49:35 -0600 |
| commit | aa1c560e5ee3cbc2c996b2af0105cdf4f55df818 (patch) | |
| tree | a57eddd814dd698a5d5d8cfeb403464bf809add7 /packages | |
| parent | 3aca9e5fa5909ba3fef3e6908eeb01a898316744 (diff) | |
| download | opencode-aa1c560e5ee3cbc2c996b2af0105cdf4f55df818.tar.gz opencode-aa1c560e5ee3cbc2c996b2af0105cdf4f55df818.zip | |
fix(desktop): hang on backtracing-prone regex
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/ui/src/components/markdown.tsx | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/packages/ui/src/components/markdown.tsx b/packages/ui/src/components/markdown.tsx index 071132e80..380a3c8a4 100644 --- a/packages/ui/src/components/markdown.tsx +++ b/packages/ui/src/components/markdown.tsx @@ -2,9 +2,18 @@ import { useMarked } from "../context/marked" import { ComponentProps, createResource, splitProps } from "solid-js" function strip(text: string): string { - const wrappedRe = /^\s*<([A-Za-z]\w*)>\s*([\s\S]*?)\s*<\/\1>\s*$/ - const match = text.match(wrappedRe) - return match ? match[2] : text + const trimmed = text.trim() + const match = trimmed.match(/^<([A-Za-z]\w*)>/) + if (!match) return text + + const tagName = match[1] + const closingTag = `</${tagName}>` + if (trimmed.endsWith(closingTag)) { + const content = trimmed.slice(match[0].length, -closingTag.length) + return content.trim() + } + + return text } export function Markdown( |
