Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(chat): pass a file:// link's already-decoded path to Show in folder unchanged

AdityaUmale4f0fcd2a8ff9
diff --git a/src/components/ChatMarkdown.test.ts b/src/components/ChatMarkdown.test.ts
index ac2f003b26..2c67f0aee8 100644
--- a/src/components/ChatMarkdown.test.ts
+++ b/src/components/ChatMarkdown.test.ts
@@ -975,6 +975,16 @@ describe("ChatMarkdown attachments", () => {
}
});
+ it("keeps a # or an escape in a file:// link's already-decoded path", () => {
+ const save = outsideSave();
+ try {
+ const html = renderToStaticMarkup(createElement(ChatMarkdown, { text: "[report](file:///tmp/Reports%23Final/100%2520x/)", message: { threadId: "thread-1", messageId: "message-1" } }));
+ expect(html).toContain(">/tmp/Reports#Final/100%20x/</code>");
+ } finally {
+ save.mockRestore();
+ }
+ });
+
it("asks the desktop app to show the real folder", async () => {
const save = outsideSave();
const ogb = (window as { ogb?: unknown }).ogb;
diff --git a/src/components/ChatMarkdown.tsx b/src/components/ChatMarkdown.tsx
index b1112e845a..71a2d067e9 100644
--- a/src/components/ChatMarkdown.tsx
+++ b/src/components/ChatMarkdown.tsx
@@ -339,7 +339,7 @@ export function MermaidDiagram({ code }: MermaidDiagramProps) {
// Security: no href at all, since an <a href="file://…"> reaches setWindowOpenHandler on a middle or modifier click,
// which calls shell.openExternal without main's containment check.
// source: the original a delivered copy came from, offered on right-click (Show in Finder) like in the gallery.
-function LocalFileLink({ filePath, name, source, children, message }: { filePath: string; name?: string; source?: string; children?: ReactNode; message?: MessageAttachmentContext }) {
+function LocalFileLink({ filePath, shownPath, name, source, children, message }: { filePath: string; shownPath: string; name?: string; source?: string; children?: ReactNode; message?: MessageAttachmentContext }) {
const save = useLocalFileSave(filePath, name, message);
const preview = useHtmlPreview(filePath, name ?? fileName(filePath), message);
const revealMenu = useRevealOriginalMenu();
@@ -391,7 +391,7 @@ function LocalFileLink({ filePath, name, source, children, message }: { filePath
)}
{save.state === "failed" && save.outsideWorkspace && (
<span className="inline-flex flex-wrap items-center gap-x-1.5 text-[12px]">
- <OutsideWorkspaceFile filePath={decodedLinkPath(filePath)} />
+ <OutsideWorkspaceFile filePath={shownPath} />
</span>
)}
{save.folder && <MessageFolderFiles folderPath={filePath} listing={save.folder} message={message} />}
@@ -659,7 +659,9 @@ function MarkdownLink({ href, children, ...rest }: { href?: string; children?: R
if (localPath) {
const copy = delivered && Object.hasOwn(delivered, fileName(localPath)) ? delivered[fileName(localPath)] : undefined;
const source = copy && originals && Object.hasOwn(originals, copy) ? originals[copy] : undefined;
- return <LocalFileLink filePath={copy ?? localPath} name={copy ? fileName(localPath) : undefined} source={source} message={message}>{children}</LocalFileLink>;
+ // localFilePath already decodes a file:// URL; a plain path link is still encoded and gets the server's single decode.
+ const shownPath = copy ?? (/^file:\/\//i.test(href) ? localPath : decodedLinkPath(localPath));
+ return <LocalFileLink filePath={copy ?? localPath} shownPath={shownPath} name={copy ? fileName(localPath) : undefined} source={source} message={message}>{children}</LocalFileLink>;
}
if (!/^https?:\/\//i.test(href)) {
return (