fix(opencode): escape {env:} substitutions to keep config JSON valid#32786
Open
ozpool wants to merge 1 commit into
Open
fix(opencode): escape {env:} substitutions to keep config JSON valid#32786ozpool wants to merge 1 commit into
ozpool wants to merge 1 commit into
Conversation
Env var substitution injected the raw value into the config text before
parsing, so a value containing backslashes (e.g. a native Windows path)
or quotes produced invalid JSON and failed to load. Mirror the {file:}
branch and JSON-escape the substituted value.
6 tasks
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 #32695
Type of change
What does this PR do?
{env:VAR}substitution in config text inserted the raw environment value directly into the JSON source before parsing. When the value contains characters that are significant inside a JSON string — most commonly backslashes in a native Windows path (C:\Users\me\...), but also quotes or newlines — the result was invalid JSON and the config failed to load on startup.The sibling
{file:...}substitution in the same function already guards against this by emittingJSON.stringify(content).slice(1, -1). This change applies the same escaping to the{env:VAR}value so the substituted string is always valid inside its surrounding JSON string. Plain values (tokens, usernames, URLs) are unaffected since escaping a string with no special characters returns it unchanged.How did you verify your code works?
Added a unit test in
packages/opencode/test/config/config.test.tsthat sets an env var to a Windows-style path containing backslashes, references it via{env:VAR}, and asserts the config loads with the value intact. The test fails on the previous code (config parse error) and passes with the fix.bun test test/config/config.test.ts,tsgo --noEmitfor the package, and Prettier all pass.Screenshots / recordings
Not a UI change.
Checklist