fix(app): handle Windows paths in frontend file URL encoding#12601
fix(app): handle Windows paths in frontend file URL encoding#12601adamdotdevin merged 1 commit intoanomalyco:devfrom
Conversation
Fixes Windows path encoding in frontend's encodeFilePath() function that was causing ERR_INVALID_URL errors when mentioning files on Windows. The frontend encodeFilePath() function didn't handle Windows backslashes, causing paths like D:\path\file.txt to be encoded as D%3A%5Cpath%5C... which creates invalid file:// URLs. This only affected the frontend since the backend correctly uses pathToFileURL() from Bun. Changes: - Normalize Windows backslashes to forward slashes - Add leading / for Windows absolute paths (D: -> /D:) - Preserve proper encoding for special characters (#, ?, %, spaces) Testing: - 46 tests added (36 unit, 10 integration) - Covers Windows, Linux, macOS paths - Tests exact bug scenario, edge cases, cross-platform compatibility - All existing tests still pass
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
Related to #12424 comment by @alexyaroshuk I do not have the windows machine :D |
|
Hi @adamdotdevin, please help me review the PR before releasing the new version. I don't want to harm the windows version... |
Just tested - the bug is fixed in this pr. |
Thank you @alexyaroshuk! |
|
Hi @rekram1-node could you help me review this PR please? Thank you! |
Fixes #12424 (comment: #12424 (comment))
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 likeD:\dev\projects\opencode\README.mdget encoded asD%3A%5Cdev%5Cprojects%5C...instead of/D:/dev/projects/..., resulting in invalid file:// URLs:Solution
/for Windows absolute paths (D: → /D:)pathToFileURL()correctly (fixed in fix: properly encode file URLs with special characters #12424)Changes
Frontend Files (4 files)
packages/app/src/context/file/path.ts- UpdatedencodeFilePath()to handle Windows backslashespackages/app/src/components/prompt-input/build-request-parts.ts- Updated duplicateencodeFilePath()functionpackages/app/src/context/file/path.test.ts- Added 34 new tests for Windows/Linux/macOS pathspackages/app/src/components/prompt-input/build-request-parts.test.ts- Added 8 integration testsTesting
✅ 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:
4 files changed, 149 insertions(+), 8 deletions(-)
Verification
@alexyaroshuk Can you verify this fixes the file mentioning issue on your Windows machine?