From 7442323ca2f0d0af756fa3e7a0385ed01d3e9c00 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Thu, 16 Apr 2026 18:04:17 +0700 Subject: [PATCH] fix(server): preserve JSON args for Windows PowerShell shims --- packages/server/src/utils/executable.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/server/src/utils/executable.ts b/packages/server/src/utils/executable.ts index 3191699c9..84a53543f 100644 --- a/packages/server/src/utils/executable.ts +++ b/packages/server/src/utils/executable.ts @@ -45,7 +45,18 @@ export function isWindowsPowerShellScript(executablePath: string): boolean { } export function windowsPowerShellScriptArgs(scriptPath: string, args: string[]): string[] { - return ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath, ...args]; + const argvBase64 = Buffer.from(JSON.stringify(args), "utf16le").toString("base64"); + const escapedScriptPath = scriptPath.replace(/'/g, "''"); + const command = [ + "$ErrorActionPreference = 'Stop'", + `$argvJson = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String('${argvBase64}'))`, + "$argv = @((ConvertFrom-Json -InputObject $argvJson))", + `& '${escapedScriptPath}' @argv`, + "exit $LASTEXITCODE", + ].join("; "); + const encodedCommand = Buffer.from(command, "utf16le").toString("base64"); + + return ["-NoProfile", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encodedCommand]; } async function probeExecutable(executablePath: string): Promise {