The best way to control Claude Code, Codex and more from any computer or phone
fix(web): copied email links keep their destination (#36830)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 18:14 UTC
bf746695091e6051c0ccf088b7621f975d176b19
3 files changed
+100
-4
apps/web/src/markdown-clipboard.test.ts
+53
@@ -216,6 +216,59 @@ describe("serializeRenderedMarkdownFragment", () => {
216
expect(paragraph.children.find((child) => child.type === "inlineCode")?.value).toBe(value);
217
});
218
219
+ it("copies email links with their address and drops in-app destinations", () => {
220
+ const container = new FakeElement("DIV").append(
221
+ new FakeElement("P").append(
222
+ new FakeText("Write to "),
223
+ new FakeElement("A", [], { href: "mailto:support@example.com" }).append(
224
+ new FakeText("support@example.com"),
225
+ ),
226
+ new FakeText(", "),
227
+ new FakeElement("A", [], { href: "mailto:support@example.com?subject=Help" }).append(
228
+ new FakeText("Support"),
229
+ ),
230
+ new FakeText(", "),
231
+ new FakeElement("A", [], { href: "mailto:support@example.com?subject=Help)" }).append(
232
+ new FakeText("Support"),
233
+ ),
234
+ new FakeText(" or "),
235
+ new FakeElement("A", [], { href: "/environment-one/thread-one" }).append(
236
+ new FakeText("the thread"),
237
+ ),
238
+ new FakeText("."),
239
+ ),
240
+ );
241
+ const copied = serializeRenderedMarkdownFragment(asNode(container));
242
+ expect(copied).toBe(
243
+ "Write to support@example.com, [Support](mailto:support@example.com?subject=Help), [Support](mailto:support@example.com?subject=Help\\)) or the thread.",
244
+ );
245
+ const paragraph = parseMarkdownWithMath(copied).children[0];
246
+ if (paragraph?.type !== "paragraph") throw new Error("Expected a paragraph");
247
+ expect(
248
+ paragraph.children.filter((child) => child.type === "link").map((link) => link.url),
249
+ ).toEqual([
250
+ "mailto:support@example.com",
251
+ "mailto:support@example.com?subject=Help",
252
+ "mailto:support@example.com?subject=Help)",
253
+ ]);
254
+ });
255
+
256
+ it.each([
257
+ "support@example.com?subject=Help",
258
+ "foo",
259
+ "support@example.internal1",
260
+ "support@example.com_",
261
+ "support@example.com-",
262
+ ])("keeps the destination when the email label is not a bare address: %s", (label) => {
263
+ const href = `mailto:${label}`;
264
+ const anchor = new FakeElement("A", [], { href }).append(new FakeText(label));
265
+ const container = new FakeElement("DIV").append(anchor);
266
+ const paragraph = parseMarkdownWithMath(serializeRenderedMarkdownFragment(asNode(container)))
267
+ .children[0];
268
+ if (paragraph?.type !== "paragraph") throw new Error("Expected a paragraph");
269
+ expect(paragraph.children.find((child) => child.type === "link")?.url).toBe(href);
270
+ });
271
+
272
it("copies alert and insight callouts as their Markdown instead of the rendered label", () => {
273
// The shape ChatMarkdown renders for `> [!WARNING]\n> Back up first.`.
274
const callout = new FakeElement("DIV", [], {
apps/web/src/markdown-clipboard.ts
+9
-4
@@ -206,12 +206,17 @@ function serializeAnchor(anchor: Element, inTableCell: boolean): string {
206
const markdownCopy = anchor.getAttribute("data-markdown-copy");
207
if (markdownCopy !== null) return escapeTablePipes(markdownCopy, inTableCell);
208
const content = serializeChildren(anchor, inTableCell);
209
- const href = escapeTablePipes(anchor.getAttribute("href") ?? "", inTableCell);
210
- if (!/^https?:\/\//i.test(href)) return content;
209
+ const href = anchor.getAttribute("href") ?? "";
210
+ if (!/^(?:https?:\/\/|mailto:)/i.test(href)) return content;
211
const label = content.trim();
212
if (!label) return "";
213
- if (label === href) return href;
214
- return `[${label}](${href})`;
213
+ const cellHref = escapeTablePipes(href, inTableCell);
214
+ if (cellHref === label) return label;
215
+ // GFM autolinks a bare address only when it fits this shape.
216
+ if (cellHref === `mailto:${label}` && /^[\w.+-]+@[\w-]+(?:\.[\w-]+)+(?<=[a-zA-Z])$/.test(label))
217
+ return label;
218
+ const destination = escapeTablePipes(href.replace(/[\\()]/g, "\\$&"), inTableCell);
219
+ return `[${label}](${destination})`;
220
}
221
222
/**
scripts/scenarios/copied-email-link-keeps-its-address.e2e.ts
new
+38
@@ -0,0 +1,38 @@
1
+/// <reference lib="dom" />
2
+// The DOM lib types the function this scenario runs in the page.
3
+import { expect } from "e2e";
4
+
5
+import { test, WEB } from "./t3.ts";
6
+
7
+const MESSAGE = "Contact [Support](mailto:support@example.com?subject=Help) for help.";
8
+
9
+test(
10
+ "A copied message pastes its labelled email link with the address",
11
+ WEB,
12
+ async ({ t3, app, browser, screen }) => {
13
+ const project = await t3.project("demo");
14
+ const thread = await t3.thread({ project, title: "Support", messages: [MESSAGE] });
15
+ await t3.open(thread);
16
+ // A message sent through the CLI shows collapsed under its sender.
17
+ await screen.getByRole("button", /^Agent Contact/).tap();
18
+ await expect(screen.getByRole("link", "Support")).toBeVisible();
19
+
20
+ // Select the rendered paragraph as a drag across it would.
21
+ await browser.evaluate(() => {
22
+ const paragraph = document.querySelector('a[href^="mailto:"]')?.closest("p");
23
+ if (!paragraph) throw new Error("No rendered email link");
24
+ const range = document.createRange();
25
+ range.selectNodeContents(paragraph);
26
+ window.getSelection()?.removeAllRanges();
27
+ window.getSelection()?.addRange(range);
28
+ return null;
29
+ });
30
+ await browser.keyboard.press("ControlOrMeta+C");
31
+
32
+ const composer = screen.getByRole("textbox");
33
+ await composer.tap();
34
+ await browser.keyboard.press("ControlOrMeta+V");
35
+ await app.screenshot("pasted");
36
+ await expect(composer).toContainText(MESSAGE);
37
+ },
38
+);