Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix: open Windows file links in chat #5283

Closedthiscallnet(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5283/headopened View on GitHub

Showing 3 changed files with 42 additions and 4 deletions.

x
0 of 3 viewed, 3 left
8 additions and 1 deletionapps/web/src/components/ChatMarkdown.tsxModified
View file
@@ -128,6 +128,10 @@
MAX_HIGHLIGHT_CACHE_MEMORY_BYTES,
​
+const WINDOWS_DRIVE_LINK_PROTOCOLS = Array.from(
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+);
+​
function findTaskListMarkerOffset(markdown: string, listItemStart: number): number | null {
const firstLineEnd = markdown.indexOf("\n", listItemStart);
const firstLine = markdown.slice(
@@ -147,7 +151,10 @@
protocols: {
...defaultSchema.protocols,
- href: [...(defaultSchema.protocols?.href ?? []), "file"],
+ // rehype-sanitize runs before react-markdown's urlTransform. A Windows
+ // drive letter looks like a protocol (`C:`), so allow drive letters here;
+ // urlTransform only preserves values with a drive-path shape afterward.
+ href: [...(defaultSchema.protocols?.href ?? []), "file", ...WINDOWS_DRIVE_LINK_PROTOCOLS],
} satisfies Parameters<typeof rehypeSanitize>[0];
​
24 additions and 2 deletionsapps/web/src/markdown-links.test.tsModified
View file
@@ -21,17 +21,39 @@
});