fix(site/src/pages/AgentsPage/components/ChatConversation): keep balanced parentheses in preview link destinations

A link or image destination such as `https://example.com/a_(b)` ended
at its first `)`, so the preview title kept the rest of the URL and the
closing parenthesis. Allow one level of balanced parentheses inside the
destination.
This commit is contained in:
Michael Suchacz
2026-10-01 17:29:46 +00:00
parent 21ccca7055
commit f37ca3e8a8
2 changed files with 13 additions and 2 deletions
@@ -58,6 +58,17 @@ describe("getThinkingDisclosureDisplay", () => {
});
});
it.each([
"See [docs](https://example.com/a_(b)) next",
"See ![docs](https://example.com/a_(b).png) next",
])("keeps balanced parentheses in link destinations: %j", (text) => {
expect(getThinkingDisclosureDisplay(text)).toEqual({
title: "See docs next",
ariaLabel: "Thinking: See docs next",
body: text,
});
});
it("keeps text that Markdown renders literally in the preview title", () => {
const text =
"Check `Promise<User>`, `*args*`, 0 < n and n > 0 in user_id_field and APP__DB__URL";
@@ -55,8 +55,8 @@ const cleanHeadingText = (text: string): string => {
return code === undefined ? match : setAside(getCodeSpanText(code));
},
)
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
.replace(/!\[([^\]]*)\]\((?:[^()]|\([^()]*\))*\)/g, "$1")
.replace(/\[([^\]]+)\]\((?:[^()]|\([^()]*\))*\)/g, "$1")
.replace(/\*\*([^*\s](?:[^*]*[^*\s])?)\*\*/g, "$1")
.replace(/\b__([^_]+)__\b/g, "$1")
.replace(/\*([^*\s](?:[^*]*[^*\s])?)\*/g, "$1")