Repository navigation
fix(shared): pasted website links with destination padding keep thread URL labels #48482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
51bc634
5e3f7fc
f2fd045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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`\[(?<label>${LABEL})\]\(${DESTINATION_PADDING}${THREAD_DESTINATION}`, | ||
| String.raw`\[${LABEL}\]\((?:<[^<>\r\n]*>|[^\s()]*(?:\([^\s()]*\)[^\s()]*)*)(?:${TITLE_SEPARATOR}${LINK_TITLE})?${DESTINATION_END}`, | ||
| // A bare destination is read by readDestination, which balances nested parentheses and escapes. | ||
| String.raw`\[${LABEL}\]\((?:${DESTINATION_PADDING}(?:<[^<>\r\n]*>(?:${TITLE_SEPARATOR}${LINK_TITLE})?${DESTINATION_END}|(?<siteHref>(?=[^\s)<])))|${DESTINATION_END})`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve escaped angle brackets in website destinations. For
|
||
| String.raw`<(?<autolink>${THREAD_HREF}[^\s<>]+|${HOSTED_LINK})>`, | ||
| // After a URL character the hosted link is part of a longer URL, such as a redirect target. | ||
| String.raw`(?<![A-Za-z0-9%/?#=&@+-])(?<bare>${HOSTED_LINK})(?!\.*[\w%/?#-])`, | ||
|
|
@@ -483,7 +484,7 @@ function parsedLinkSource(markdown: string) { | |
| } | ||
|
|
||
| function readDestination(markdown: string, match: RegExpExecArray) { | ||
| const start = match.index + match[0].length - match.groups!.customHref!.length; | ||
| const start = match.index + match[0].length - (match.groups!.customHref?.length ?? 0); | ||
| for (let i = start, depth = 0; i < markdown.length; i++) { | ||
| const ch = markdown[i]!; | ||
| if (ch === "\\" && /[!-/:-@[-`{-~]/.test(markdown[i + 1] ?? "")) i++; | ||
|
|
@@ -557,6 +558,8 @@ export function replaceThreadLinks( | |
| if (parsed) ({ href, end: pattern.lastIndex } = parsed); | ||
| else if (match.groups?.customHref) | ||
| ({ href, end: pattern.lastIndex } = readDestination(markdown, match)); | ||
| else if (match.groups?.siteHref !== undefined) | ||
| pattern.lastIndex = readDestination(markdown, match).end; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium Malformed input with repeated 🤖 Copy this AI Prompt to have your agent fix this: |
||
| const link = href === undefined ? null : parseThreadLinkHref(href); | ||
| const flatLabel = match.groups?.label; | ||
| const label = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /// <reference lib="dom" /> | ||
| import { expect } from "e2e"; | ||
|
|
||
| import { test, WEB } from "./t3.ts"; | ||
|
|
||
| test( | ||
| "Pasting a padded website link keeps its thread URL label", | ||
| WEB, | ||
| async ({ t3, app, browser, screen }) => { | ||
| const project = await t3.project("demo"); | ||
| const linked = await t3.thread({ | ||
| project, | ||
| title: "Release checklist", | ||
| messages: ["Draft the checklist"], | ||
| }); | ||
| const target = await t3.thread({ project, title: "Release notes", messages: ["Start"] }); | ||
| await t3.open(target); | ||
| const composer = screen.getByRole("textbox"); | ||
| await composer.tap(); | ||
|
|
||
| await browser.evaluate((threadId) => { | ||
| const environment = window.location.pathname.split("/")[1]; | ||
| const href = `https://app.t3.codes/threads/${environment}/${encodeURIComponent(threadId)}`; | ||
| const clipboardData = new DataTransfer(); | ||
| clipboardData.setData( | ||
| "text/plain", | ||
| `See [${href}]( https://example.com "Example") and ${href}`, | ||
| ); | ||
| const editor = document.activeElement; | ||
| if (!editor?.matches('[contenteditable="true"]')) throw new Error("Composer is not focused"); | ||
| return editor.dispatchEvent( | ||
| new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }), | ||
| ); | ||
| }, linked.threadId); | ||
|
|
||
| const chip = composer.getByText("Release checklist", { exact: true }); | ||
| await chip.first().waitFor(); | ||
| await app.screenshot("pasted-website-link"); | ||
| await expect(chip).toHaveCount(1); | ||
| await expect(composer.getByText(/\[https:\/\/app\.t3\.codes\/threads\//)).toBeVisible(); | ||
| }, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
src/threadLinks.ts:68[https://app.t3.codes/threads/there/t1]( "two words")is treated as a bare destination, soreadDestinationfails at the space in the title and the URL inside the label is incorrectly emitted as a thread chip. The pattern has no title-only alternative afterDESTINATION_PADDING; add one before thesiteHrefbranch.🤖 Copy this AI Prompt to have your agent fix this: