[PR #12601] fix(app): handle Windows paths in frontend file URL encoding #14291

Closed
opened 2026-02-16 18:19:06 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12601

State: closed
Merged: Yes


Fixes anomalyco/opencode#12424 (comment: https://github.com/anomalyco/opencode/pull/12424#issuecomment-3864133699)

Summary

Fixes bug introduced in PR #12424 where Windows users cannot mention files. The frontend's encodeFilePath() function doesn't handle Windows backslashes, causing invalid file:// URLs on Windows.

Root Cause

Frontend path encoding splits by / but Windows uses \. Paths like D:\dev\projects\opencode\README.md get encoded as D%3A%5Cdev%5Cprojects%5C... instead of /D:/dev/projects/..., resulting in invalid file:// URLs:

TypeError: "file://D%3A%5Cdev%5Cprojects%5Copencode/README.bs.md" cannot be parsed as a URL.

Solution

  • Normalize Windows backslashes to forward slashes before encoding
  • Add leading / for Windows absolute paths (D: → /D:)
  • Preserve proper encoding for special characters (#, ?, %, spaces)
  • Backend already uses pathToFileURL() correctly (fixed in #12424)

Changes

Frontend Files (4 files)

  • packages/app/src/context/file/path.ts - Updated encodeFilePath() to handle Windows backslashes
  • packages/app/src/components/prompt-input/build-request-parts.ts - Updated duplicate encodeFilePath() function
  • packages/app/src/context/file/path.test.ts - Added 34 new tests for Windows/Linux/macOS paths
  • packages/app/src/components/prompt-input/build-request-parts.test.ts - Added 8 integration tests

Testing

46 tests pass, 0 fail - All unit and integration tests
TypeScript clean - No type errors
Windows paths: Tests exact bug scenario from @alexyaroshuk
Cross-platform: Tests Windows (D:\path), Linux (/path), macOS paths
Special chars: Tests #, ?, %, spaces in filenames
Backward compatible: Normal paths produce identical output

Impact

Fixes:

  • File mentioning with @ on Windows (reported by @alexyaroshuk)
  • File URL construction for Windows absolute paths
  • Cross-platform compatibility for path encoding

4 files changed, 149 insertions(+), 8 deletions(-)

Verification

@alexyaroshuk Can you verify this fixes the file mentioning issue on your Windows machine?

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12601 **State:** closed **Merged:** Yes --- Fixes anomalyco/opencode#12424 (comment: https://github.com/anomalyco/opencode/pull/12424#issuecomment-3864133699) ## Summary Fixes bug introduced in PR #12424 where Windows users cannot mention files. The frontend's `encodeFilePath()` function doesn't handle Windows backslashes, causing invalid file:// URLs on Windows. ### Root Cause Frontend path encoding splits by `/` but Windows uses `\`. Paths like `D:\dev\projects\opencode\README.md` get encoded as `D%3A%5Cdev%5Cprojects%5C...` instead of `/D:/dev/projects/...`, resulting in invalid file:// URLs: ``` TypeError: "file://D%3A%5Cdev%5Cprojects%5Copencode/README.bs.md" cannot be parsed as a URL. ``` ### Solution - Normalize Windows backslashes to forward slashes before encoding - Add leading `/` for Windows absolute paths (D: → /D:) - Preserve proper encoding for special characters (#, ?, %, spaces) - Backend already uses `pathToFileURL()` correctly (fixed in #12424) ## Changes ### Frontend Files (4 files) - `packages/app/src/context/file/path.ts` - Updated `encodeFilePath()` to handle Windows backslashes - `packages/app/src/components/prompt-input/build-request-parts.ts` - Updated duplicate `encodeFilePath()` function - `packages/app/src/context/file/path.test.ts` - Added 34 new tests for Windows/Linux/macOS paths - `packages/app/src/components/prompt-input/build-request-parts.test.ts` - Added 8 integration tests ## Testing ✅ **46 tests pass, 0 fail** - All unit and integration tests ✅ **TypeScript clean** - No type errors ✅ **Windows paths**: Tests exact bug scenario from @alexyaroshuk ✅ **Cross-platform**: Tests Windows (`D:\path`), Linux (`/path`), macOS paths ✅ **Special chars**: Tests `#`, `?`, `%`, spaces in filenames ✅ **Backward compatible**: Normal paths produce identical output ## Impact **Fixes:** - File mentioning with @ on Windows (reported by @alexyaroshuk) - File URL construction for Windows absolute paths - Cross-platform compatibility for path encoding **4 files changed, 149 insertions(+), 8 deletions(-)** ## Verification @alexyaroshuk Can you verify this fixes the file mentioning issue on your Windows machine?
yindo added the pull-request label 2026-02-16 18:19:06 -05:00
yindo closed this issue 2026-02-16 18:19:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14291