fix(path): do not decode percent-encoding in raw filesystem paths#18356
Closed
ernestodeoliveira wants to merge 1 commit intoanomalyco:devfrom
Closed
fix(path): do not decode percent-encoding in raw filesystem paths#18356ernestodeoliveira wants to merge 1 commit intoanomalyco:devfrom
ernestodeoliveira wants to merge 1 commit intoanomalyco:devfrom
Conversation
When a project path contains a literal percent-encoded sequence in the directory name (e.g. D:\First%20Second), normalize() was calling decodeURIComponent() unconditionally, silently converting the literal %20 to a space and resolving a different — non-existent — directory. Fix: apply decodeFilePath only when the input is a file:// URL. Raw filesystem paths (Windows or Unix) may contain literal % characters that are part of the folder/file name and must not be decoded. Adds regression tests for both the preserved-literal case and the expected decode-on-file-url case. Fixes anomalyco#18285
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Contributor
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
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 #18285.
When a project path contains a literal percent-encoded sequence in the directory name (e.g.
D:\First%20Second), opencode was silently decoding%20to a space, resolving the path asD:\First Second— a different, non-existent directory.Root Cause
In
packages/app/src/context/file/path.ts, thenormalize()function always calleddecodeFilePath()(which runsdecodeURIComponent()) on the raw input:decodeFilePathis only needed when the input is afile://URL (to convertfile:///home/user/My%20Docs→/home/user/My Docs). Raw filesystem paths — Windows or Unix — may contain literal%20or other%XXsequences as part of the actual folder/file name. Decoding those is incorrect.Fix
Guard
decodeFilePathbehind anisUrlcheck:Testing
Added 2 regression tests to
path.test.ts:%20in raw Windows path is preserved —D:\First%20Second\file.txtnormalizes correctly without decoding%20infile://URL is still decoded —file:///home/user/My%20Documents/file.txtcontinues to work as beforeAll 39 existing tests pass.
Notes
The typecheck pre-push hook fails on
@opencode-ai/enterprise(src/custom-elements.d.ts) — this error exists ondevbefore this change and is unrelated to this fix.