@devries-cameron20 / t3code Mirror · read-only / commits / 7556047418
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 17:15 UTC

fix(web): copying an image with a spaced path keeps it an image (#35914)

Julius Marminge committed Nov 12, 2026 at 19:54 UTC 75560474189031f3f5553aee56386230fdaeff36
2 files changed +27 -2
apps/web/src/components/chat/ChatMarkdownMedia.browser.test.tsx
+14 -1
@@ -1,9 +1,11 @@
1 import type { PreparedConnection } from "@t3tools/client-runtime/connection";
2 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3 +import remarkParse from "remark-parse";
4 +import { unified } from "unified";
5 import { describe, expect, it, vi } from "vite-plus/test";
6
7 import { render } from "../../../test/render";
6 -import { ChatMarkdownAssetImage } from "./ChatMarkdownMedia";
8 +import { ChatMarkdownAssetImage, markdownImageCopy } from "./ChatMarkdownMedia";
9
10 // Every evaluation of the URL query is one mint: the first read, then one per refresh.
11 const assetQuery = vi.hoisted(() => ({ mints: 0 }));
@@ -84,3 +86,14 @@ describe("ChatMarkdownAssetImage", () => {
86 expect(assetQuery.mints).toBe(2);
87 });
88 });
89 +
90 +describe("markdownImageCopy", () => {
91 + it("copies an image whose path has a space as Markdown that is still that image", () => {
92 + // Raw HTML <img> and <picture> sources reach the copy with the space unencoded.
93 + const copied = markdownImageCopy("Shot", "/work/my shot.png", undefined);
94 + const [block] = unified().use(remarkParse).parse(copied).children;
95 + const images =
96 + block?.type === "paragraph" ? block.children.filter((node) => node.type === "image") : [];
97 + expect(images.map((image) => decodeURI(image.url))).toEqual(["/work/my shot.png"]);
98 + });
99 +});
apps/web/src/components/chat/ChatMarkdownMedia.tsx
+13 -1
@@ -37,7 +37,19 @@ export function markdownImageCopy(alt: string, src: string, title: string | unde
37 const escapedAlt = alt.replaceAll("\\", "\\\\").replaceAll("[", "\\[").replaceAll("]", "\\]");
38 const titleSuffix =
39 title === undefined ? "" : ` "${title.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
40 - return `![${escapedAlt}](${src}${titleSuffix})`;
40 + return `![${escapedAlt}](${markdownDestination(src)}${titleSuffix})`;
41 +}
42 +
43 +// Raw HTML sources keep spaces and parentheses that a bare Markdown destination cannot hold.
44 +function markdownDestination(src: string): string {
45 + if (!/[\s<>()]/.test(src)) return src;
46 + const escaped = src
47 + .replaceAll("\\", "\\\\")
48 + .replaceAll("<", "\\<")
49 + .replaceAll(">", "\\>")
50 + .replaceAll("\n", "%0A")
51 + .replaceAll("\r", "%0D");
52 + return `<${escaped}>`;
53 }
54
55 /**