Conversation
Contributor
|
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. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This branch has not been deployed
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.
Issue for this PR
Closes #51148
Type of change
What does this PR do?
substitute()(packages/core/src/config/variable.ts) runs on raw JSON(C) config text before parsing and passes the{file:...}body straight to the filesystem without decoding JSON string escapes. In a JSON string value every backslash is doubled, so a UNC path like\\server\share\mcp.jsonreachesreadFileStringas\\\\server\\share\\mcp.jsonand fails withbad file reference ... does not exist. The substituted file content is re-escaped on the way out (JSON.stringify(...).slice(1, -1)), which confirms these tokens live inside JSON strings — the escapes just were not decoded on the way in.Windows users writing configs through any JSON serializer hit this for every
{file:...}reference with a backslash path. Forward-slash paths work, which is why it hides depending on which tool wrote the config.Fix: after extracting the token body, decode it with
JSON.parse, falling back to the raw path when the body is not valid JSON string content (preserving behavior for hand-written configs). All three v2 call sites (loadFile, well-known configs,OPENCODE_CONFIG_CONTENT) substitute pre-parse JSON(C) text, so no opt-in flag is needed. This is the fix from #51163 (closed: it targeted the v1devbranch) reworked for v2, where the logic was rewritten intopackages/core— the v1 version used a flag because the v1 tree also had call sites receiving already-decoded strings; v2 has none.How did you verify your code works?
New tests in
packages/core/test/config/variable.test.tsuse a spy FS layer recording the exact path handed to the filesystem:\\server\share\...,C:\Users\...) decode before resolution~\/decodes before~expansionBefore the fix, the UNC / Windows-path /
~\/tests fail on the undecoded literal; after, all 5 pass. A real UNC server isn't available locally or in CI, hence the spy layer.bun test test/config/: 207 pass, and the 6 failing tests (home-dir.claude/.agentsdiscovery) fail identically on a clean checkout ofv2— unrelated to this change. Typecheck reports no diagnostics in the touched files.Screenshots / recordings
N/A (no UI change)
Checklist