Skip to content

Commit 4e62f49

Browse files
committed
fix(shared): file links in angle brackets keep a parenthesis in the path
1 parent 7da6dc9 commit 4e62f49

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎packages/shared/src/markdownPipeline.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ const linkDestinationProcessor = unified().use(remarkParse).use(remarkKeepWindow
421421
export function decodeMarkdownLinkEscapes(href: string): string {
422422
// Only the parser knows character references, so destinations that may have one go through it.
423423
if (href.includes("&")) {
424-
const destination = /\s/.test(href) ? `<${href}>` : href;
424+
// The extractor drops angle brackets, and only that form keeps an unmatched `)` in the path.
425+
const destination = /[<>]/.test(href) ? href : `<${href}>`;
425426
const paragraph = linkDestinationProcessor.parse(`[](${destination})`).children[0];
426427
const link = paragraph?.type === "paragraph" ? paragraph.children[0] : undefined;
427428
if (link?.type === "link") return link.url;

‎packages/shared/src/threadFindText.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ it("searches displayed prose and file-chip labels without hidden paths", () => {
104104
expect(
105105
assistantSegments("[a](/repo/a&amp;b/page.tsx) and [b](/repo/c&amp;d/page.tsx)", "/repo"),
106106
).toEqual(["a page.tsx · repo/a&b and b page.tsx · repo/c&d"]);
107+
expect(
108+
assistantSegments("[a](</repo/a&b)/page.tsx>) and [b](</repo/c&d)/page.tsx>)", "/repo"),
109+
).toEqual(["a page.tsx · repo/a&b) and b page.tsx · repo/c&d)"]);
110+
expect(
111+
assistantSegments("[a](/repo/(a)&b/page.tsx) and [b](/repo/(c)&d/page.tsx)", "/repo"),
112+
).toEqual(["a page.tsx · repo/(a)&b and b page.tsx · repo/(c)&d"]);
113+
expect(
114+
assistantSegments("[a](/repo/a&b>c/page.tsx) and [b](/repo/c&d>e/page.tsx)", "/repo"),
115+
).toEqual(["a page.tsx · repo/a&b>c and b page.tsx · repo/c&d>e"]);
107116
});
108117

109118
it("keeps fence paths literal and indexes file-chip labels in user messages", () => {

0 commit comments

Comments
 (0)