Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): keep Windows drive paths as chat file links #7182

Closedmaslinedwin(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/7182/headopened View on GitHub

What Changed

Fixes #6418. Markdown destinations like D:/... are rewritten to file:/// before sanitize, and bare Windows paths are autolinked. Workspace vs external-editor behavior is unchanged.

Why

On Windows, [Open](D:/tmp/file.md) survives Markdown parse as a link, but rehype-sanitize treats D: as an unknown protocol and strips the href before urlTransform / rewriteMarkdownFileUriHref can keep it. Bare paths such as M:\batches\...\prompt.md never become links because GFM does not autolink filesystem paths.

This preprocesses those destinations (and conservative bare drive/UNC paths) into file:/// URLs so sanitize keeps them. Existing rewriteMarkdownFileUriHref / resolveMarkdownFileLinkMeta still decide chips, tooltips, and workspace vs external-editor behavior. Drive-letter schemes are not added to the sanitize allowlist.

Checklist

  • This PR is small and focused
  • I explained what changed and why

Note

Medium Risk Adds a large regex-based markdown preprocessor on the chat render path; behavior is heavily tested but edge cases in mixed Windows paths, emphasis, and code fences could still mis-link or mis-map task checkboxes.

Overview Fixes Windows chat markdown where D:/... link destinations were stripped by rehype-sanitize (drive letter treated as a protocol) and bare paths never became links.

normalizeWindowsMarkdownFileLinks preprocesses the message before parse/render: rewrites inline/link-definition/angle-bracket Windows destinations to file:/// URLs, conservatively autolinks bare drive and UNC paths, and skips fenced code, indented code, and inline code. ChatMarkdown renders and resolves file-link metadata from this rewritten markdownSource while task-checkbox edits still target the original text.

rewriteMarkdownFileUriHref and parseFileUrlHref now handle UNC file:// URLs and pass leftover bare D:/ / UNC hrefs through so urlTransform does not drop them. findTaskListMarkerOffset moves to markdown-task-list.ts and maps AST offsets from the rewritten source back to the raw string by line when earlier autolinking shifts byte positions.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 18b22ae976c5083c3b7c40446457384b9ddfcb90. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

  • Adds normalizeWindowsMarkdownFileLinks in markdown-links.ts to preprocess chat markdown before rendering, converting bare Windows drive paths (e.g. C:\...) and UNC paths (e.g. \\server\share) into file:// links while skipping code blocks and existing links.
  • Updates parseFileUrlHref and rewriteMarkdownFileUriHref to correctly round-trip Windows drive and UNC file:// URLs back to their path forms instead of dropping them.
  • Updates ChatMarkdown.tsx to run this normalization before parsing, and introduces findTaskListMarkerOffset in markdown-task-list.ts to correctly map checkbox marker positions back to the original (pre-normalized) source when toggling task list items.
  • Behavioral Change: task list checkbox offsets are now computed against original text; rewrites earlier in the document shift parsed offsets but are now correctly remapped.
Macroscope summarized 18b22ae.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 2d1d1b92-b417-4931-aedf-510bf787fdaa

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. @@ -1382,3 +1383,4 @@
      13821383 serverConfig?.availableEditors ?? [],
      13831384 );
      13841385 const diffThemeName = resolveDiffThemeName(resolvedTheme);
      1386+ const markdownSource = useMemo(() => normalizeWindowsMarkdownFileLinks(text), [text]);
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium components/ChatMarkdown.tsx:1386

      normalizeWindowsMarkdownFileLinks(text) rewrites Windows paths inside code that CommonMark renders literally, so multi-backtick inline spans, fenced blocks containing mid-line ```/~~~ sequences, and indented code blocks can display Markdown link syntax instead of the original path. mapMarkdownOutsideCode does not recognize these code boundaries reliably; make the normalization parser-aware (or otherwise preserve all CommonMark code blocks) before passing the source to ReactMarkdown.

      Also found in 2 other location(s)

      apps/web/src/markdown-links.ts:261

      FENCED_CODE_SEGMENT_PATTERN treats any ``` or ~~~ sequence as a fence terminator, without requiring it to be on a closing-fence line. If fenced code content contains three backticks/tilde characters mid-line, protection ends there and later Windows paths inside the same code block are rewritten into links, corrupting the code sample.

      apps/web/src/markdown-links.ts:273

      mapMarkdownOutsideCode protects only fenced and inline code, so Markdown indented code blocks are passed through transform. For example, D:\tmp\file.md is rewritten into link syntax even though CommonMark renders the original line as code, changing code samples and potentially causing the rewritten line to render differently instead of preserving the code block.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/components/ChatMarkdown.tsx around line 1386:
      
      `normalizeWindowsMarkdownFileLinks(text)` rewrites Windows paths inside code that CommonMark renders literally, so multi-backtick inline spans, fenced blocks containing mid-line [code fence]/~~~ sequences, and indented code blocks can display Markdown link syntax instead of the original path. `mapMarkdownOutsideCode` does not recognize these code boundaries reliably; make the normalization parser-aware (or otherwise preserve all CommonMark code blocks) before passing the source to `ReactMarkdown`.
      
      Also found in 2 other location(s):
      - apps/web/src/markdown-links.ts:261 -- `FENCED_CODE_SEGMENT_PATTERN` treats any ` [code fence] ` or `~~~` sequence as a fence terminator, without requiring it to be on a closing-fence line. If fenced code content contains three backticks/tilde characters mid-line, protection ends there and later Windows paths inside the same code block are rewritten into links, corrupting the code sample.
      - apps/web/src/markdown-links.ts:273 -- `mapMarkdownOutsideCode` protects only fenced and inline code, so Markdown indented code blocks are passed through `transform`. For example, `    D:\tmp\file.md` is rewritten into link syntax even though CommonMark renders the original line as code, changing code samples and potentially causing the rewritten line to render differently instead of preserving the code block.
      

      Fixed in 72ff697da9838d0afec86bbd0219f813476699a2. mapMarkdownOutsideCode now walks lines: indented code (4 spaces / tab) is left alone, and a fence only closes on its own line, so mid-line ``` no longer ends the block.

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR adds substantial new markdown parsing logic for Windows path normalization. There is an unresolved Medium severity finding about potential issues with code block handling - while the author claims to have fixed it, the fix should be verified by human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 72ff697da9838d0afec86bbd0219f813476699a2. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      Closing in favor of merged #8081, which fixes Windows drive-path file links in chat. Bare-path and UNC autolinking were not included and can be proposed separately as a focused follow-up. Your work is credited in #8081.

Sign in to join this conversation.