fix: properly encode file URLs with special characters#12424
Open
yudgnahk wants to merge 3 commits intoanomalyco:devfrom
Open
fix: properly encode file URLs with special characters#12424yudgnahk wants to merge 3 commits intoanomalyco:devfrom
yudgnahk wants to merge 3 commits intoanomalyco:devfrom
Conversation
Fixes 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 Fixes anomalyco#11790 Partially fixes anomalyco#9804 May improve anomalyco#9173, anomalyco#8172, anomalyco#8759, anomalyco#11630 11 files changed, 102 insertions(+), 21 deletions(-)
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (7 files)
packages/opencode/src/session/prompt.ts- Fixed 2 occurrencespackages/opencode/src/cli/cmd/run.ts- Fixed 1 occurrencepackages/opencode/src/acp/agent.ts- Fixed 4 occurrencespackages/opencode/src/lsp/index.ts- Fixed decoding withfileURLToPath()packages/opencode/src/cli/cmd/tui/component/dialog-status.tsx- Fixed 1 occurrencepackages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx- Fixed 1 occurrencepackages/opencode/test/session/prompt-special-chars.test.ts- Added test case for#characterFrontend Files (2 files)
packages/app/src/components/prompt-input.tsx- CustompathToFileUrl()helperpackages/app/src/context/file.tsx-encodeFilePath()anddecodeFilePath()helpersSDK/Demo Files (2 files)
packages/sdk/js/example/example.ts- Fixed example codepackages/app/src/components/file-tree.tsx- Fixed drag-and-drop encodingTesting
✅ All tests pass:
bun test- 884 pass, 1 skip, 0 fail✅ TypeScript clean: All packages typecheck successfully
✅ Real file testing: Created test files
file#name.txt,file?name.txtand verified operations✅ Backward compatible: Normal paths produce identical output
Impact
Fixes:
@file#name.txt11 files changed, 114 insertions(+), 21 deletions(-)
Related Issues
Fixes #11790
Partially fixes #9804
May improve #9173, #8172, #8759, #11630