Skip to content

Commit f558007

Browse files
ScriptedAlchemydevin-ai-integration[bot]Yash-Singh1
authored
fix(clients): parse angle-bracketed thread link destinations (#30709)
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Yash Singh <[email protected]>
1 parent 23e3465 commit f558007

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎apps/mobile/src/lib/enrichedLinkPresentation.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,16 @@ describe("Enriched link presentation", () => {
103103
]);
104104
expect(threadChipTargets(here, "No links here.")).toEqual([]);
105105
});
106+
107+
it("finds thread links with angle-bracketed destinations", () => {
108+
const here = "env-here" as EnvironmentId;
109+
expect(threadChipTargets(here, "See [A](<t3-thread://v2/env-here/thread_a>).")).toEqual([
110+
{
111+
href: "t3-thread://v2/env-here/thread_a",
112+
environmentId: here,
113+
threadId: "thread_a",
114+
link: true,
115+
},
116+
]);
117+
});
106118
});

‎apps/mobile/src/lib/enrichedLinkPresentation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function threadChipTargets(
5858
): ReadonlyArray<ThreadChipTarget> {
5959
const targets = new Map<string, ThreadChipTarget>();
6060
if (hasThreadLinks(markdown)) {
61-
for (const [, href = ""] of markdown.matchAll(/\]\((t3-thread:\/\/v[12]\/[^\s)]+)\)/g)) {
61+
for (const [, href = ""] of markdown.matchAll(/\]\(<?(t3-thread:\/\/v[12]\/[^\s>)]+)>?\)/g)) {
6262
const link = parseThreadLinkHref(href);
6363
if (link) {
6464
targets.set(href, {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ describe("thread links", () => {
104104
).toBe("[There](t3-thread://v2/there/t1) and [Here](t3-thread://v2/local/t1)");
105105
});
106106

107+
it("reads an angle-bracketed destination as the labeled link, not an autolink", () => {
108+
const title = titlesIn({ local: { t1: "Here" }, there: { t1: "There" } });
109+
expect(
110+
relabelThreadLinks(
111+
"[old](<t3-thread://v2/there/t1>) and [older](<t3-thread://v2/local/t1>)",
112+
local,
113+
title,
114+
),
115+
).toBe("[There](t3-thread://v2/there/t1) and [Here](t3-thread://v2/local/t1)");
116+
expect(
117+
relabelThreadLinks("[Kept label](<t3-thread://v2/local/t1>)", local, () => undefined),
118+
).toBe("Kept label");
119+
expect(threadLinkRefs("[a](<t3-thread://v2/there/t2>)", local)).toEqual([ref("there", "t2")]);
120+
});
121+
107122
it("turns a v2 link it cannot resolve into plain text, never the raw link", () => {
108123
expect(
109124
relabelThreadLinks(

‎packages/shared/src/threadLinks.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const HOSTED_PREFIX = `${DEFAULT_HOSTED_APP_URL}/threads/`;
1111
const HOSTED_SEGMENT = "[A-Za-z0-9_%-]+";
1212
const HOSTED_LINK = `${HOSTED_PREFIX.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}${HOSTED_SEGMENT}/${HOSTED_SEGMENT}`;
1313
// Code comes first in the alternation so a link written inside a code span or fence is skipped.
14+
// A labeled link's destination may be angle-bracketed, as CommonMark allows: [label](<href>).
1415
const THREAD_LINK_OUTSIDE_CODE = new RegExp(
15-
String.raw`(?<fence>(\`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(\`+)[^\n]*?\4)|\[(?<label>[^\]\n]*)\]\((?<href>t3-thread:\/\/v[12]\/[^\s)]+|${HOSTED_LINK})\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+|${HOSTED_LINK})>|(?<bare>${HOSTED_LINK})(?![\w%/?#-])`,
16+
String.raw`(?<fence>(\`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(\`+)[^\n]*?\4)|\[(?<label>[^\]\n]*)\]\(<?(?<href>t3-thread:\/\/v[12]\/[^\s>)]+|${HOSTED_LINK})>?\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+|${HOSTED_LINK})>|(?<bare>${HOSTED_LINK})(?![\w%/?#-])`,
1617
"g",
1718
);
1819

0 commit comments

Comments
 (0)