diff --git a/packages/shared/src/threadLinks.test.ts b/packages/shared/src/threadLinks.test.ts index 88ddd37d41bc7..166d4ba1c5cdf 100644 --- a/packages/shared/src/threadLinks.test.ts +++ b/packages/shared/src/threadLinks.test.ts @@ -709,6 +709,26 @@ describe("hosted thread links", () => { [`[Example](https://example.com/?next=${hosted})`], [`[ ${hosted} ](https://example.com)`], [`[${hosted}]( "Title")`], + [`[${hosted}]( https://example.com "Example")`], + [`[${hosted}](\n)`], + [`[${hosted}]( "two words")`], + [`[${hosted}](b>)`], + [ + `[${hosted}]( https://example.com/a(b(c))) ${hosted}`, + `[${hosted}]( https://example.com/a(b(c))) ${relabeled}`, + ], + [ + `[${hosted}](https://example.com/a\\(b) ${hosted}`, + `[${hosted}](https://example.com/a\\(b) ${relabeled}`, + ], + [ + `[${hosted}](https://example.com/a(b ${hosted})`, + `[${relabeled}](https://example.com/a(b ${relabeled})`, + ], + [ + `[${hosted}]( https://example.com) ${hosted}`, + `[${hosted}]( https://example.com) ${relabeled}`, + ], [`[${hosted}](t3-thread://v2/local/id "Title")`], [`[a](https://example.com/x_(y)) ${hosted}`, `[a](https://example.com/x_(y)) ${relabeled}`], [`(${hosted}) **${hosted}**`, `(${relabeled}) **${relabeled}**`], @@ -726,6 +746,13 @@ describe("hosted thread links", () => { } }); + it("rewrites a hosted link after many unclosed website links", () => { + const openers = "[x](".repeat(50_000); + expect(replaceThreadLinks(`${openers} `, () => "linked")).toBe( + `${openers} linked`, + ); + }); + it("keeps Markdown reference link definitions intact when relabeling", () => { const hosted = "https://app.t3.codes/threads/local/demo"; for (const markdown of [ diff --git a/packages/shared/src/threadLinks.ts b/packages/shared/src/threadLinks.ts index 1ea778e7a9de1..6bccda7920296 100644 --- a/packages/shared/src/threadLinks.ts +++ b/packages/shared/src/threadLinks.ts @@ -64,7 +64,8 @@ const TITLE_SEPARATOR = String.raw`(?=[ \t\r\n])${DESTINATION_PADDING}`; const LINK_TITLE_END = new RegExp(`^${TITLE_SEPARATOR}${LINK_TITLE}${DESTINATION_END}`); const LINK_PATTERNS = [ String.raw`\[(?