From cfb7ad824dfbaaecc889f6155a92b106fc7b4e2f Mon Sep 17 00:00:00 2001 From: licat <1834199672@qq.com> Date: Mon, 6 Jul 2026 17:51:57 +0800 Subject: [PATCH] fix(opencode): JSON-escape {env:} values in config substitution Backslashes in env var values (common on Windows paths like C:\\Users\\...) produce invalid JSON escape sequences when inserted verbatim into config text before parsing. Use JSON.stringify() for env values, same as {file:} already does. Fixes #35536 --- packages/opencode/src/config/variable.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/config/variable.ts b/packages/opencode/src/config/variable.ts index 52c449538fa1..5e3b719ed82b 100644 --- a/packages/opencode/src/config/variable.ts +++ b/packages/opencode/src/config/variable.ts @@ -34,7 +34,9 @@ function dir(input: ParseSource) { export async function substitute(input: SubstituteInput) { const missing = input.missing ?? "error" let text = input.text.replace(/\{env:([^}]+)\}/g, (_, varName) => { - return (input.env?.[varName] ?? process.env[varName]) || "" + const val = input.env?.[varName] ?? process.env[varName] + if (!val) return "" + return JSON.stringify(val).slice(1, -1) }) const fileMatches = Array.from(text.matchAll(/\{file:[^}]+\}/g))