Uh oh!
There was an error while loading. Please reload this page.
fix: properly encode file URLs with special characters - #12424
Conversation
The following comment was made by an LLM, it may be inaccurate: I found 1 potentially related PR: Related PR:
The other match (#10049 about Windows drive letter case) is less directly related to special character encoding. |
8674278 to
57517ffCompareFixes ENOENT errors when filenames contain # ? % or other URL-reserved characters by using pathToFileURL() instead of string interpolation. Changes: - Backend: Use pathToFileURL()/fileURLToPath() from Bun/Node.js - Frontend: Custom encoding helpers (browser-compatible) - SDK Example: Fixed demo code - Drag-and-drop: Fixed file-tree.tsx encoding Fixesanomalyco#11790 Partially fixesanomalyco#9804 May improve anomalyco#9173, anomalyco#8172, anomalyco#8759, anomalyco#11630 11 files changed, 102 insertions(+), 21 deletions(-)
57517ff to
0b86aebCompareUh oh!
There was an error while loading. Please reload this page.
I cannot mention files after this commit:
938 | }) @yudgnahk Could you confirm this on your end and fix this ? |
yudgnahk
commented
Feb 7, 2026
Hi @alexyaroshuk, let me check. |
yudgnahk
commented
Feb 7, 2026
Hi @alexyaroshuk, please help me check the PR #12601 |
Summary
Fixes critical bug where filenames containing special characters (
#,?,%, spaces) caused ENOENT errors and path truncation throughout the application.Root Cause
Using string interpolation
`file://${path}`instead of proper URL encoding. The#character is treated as a URL fragment identifier, causing paths like/path/to/file#name.txtto be truncated to/path/to/file.Solution
pathToFileURL()andfileURLToPath()built-in APIs#→%23,?→%3F, etc.Changes
Backend Files (10 files)
packages/opencode/src/session/prompt.ts- Fixed 2 occurrences usingpathToFileURL()packages/opencode/src/cli/cmd/run.ts- Fixed 1 occurrence usingpathToFileURL()packages/opencode/src/acp/agent.ts- Fixed 3 occurrences usingpathToFileURL()packages/opencode/src/lsp/index.ts- Fixed decoding withfileURLToPath()packages/opencode/src/cli/cmd/tui/component/dialog-status.tsx- Fixed 1 occurrence usingfileURLToPath()packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx- Fixed 1 occurrence usingpathToFileURL()packages/opencode/test/session/prompt-special-chars.test.ts- Added comprehensive test case for#characterpackages/sdk/js/example/example.ts- Fixed SDK example code usingpathToFileURL()script/duplicate-pr.ts- Fixed duplicate-pr script usingpathToFileURL()Frontend Files (3 files)
packages/app/src/components/prompt-input/build-request-parts.ts- AddedencodeFilePath()helper, fixed file attachments and context files (2 locations)packages/app/src/context/file/path.ts- AddedencodeFilePath()anddecodeFilePath()helpers, fixednormalize()andtab()functionspackages/app/src/components/file-tree.tsx- AddedpathToFileUrl()helper, fixed drag-and-drop encodingTesting
✅ All tests pass:
bun test- 891 pass, 1 skip, 0 fail✅ TypeScript clean: All 17 packages typecheck successfully
✅ Special chars test: Verifies
#character handling end-to-end with file read/write✅ Backward compatible: Normal paths produce identical output
✅ Comprehensive coverage: All instances of
file://${...}pattern fixed across the codebaseImpact
Fixes:
@file#name.txt12 files changed, 114 insertions(+), 22 deletions(-)
Related Issues
Fixes#11790
Partially fixes#9804
May improve #9173, #8172, #8759, #11630