fix(server): preserve JSON args for Windows PowerShell shims

This commit is contained in:
Mohamed Boudra
2026-04-16 18:04:17 +07:00
parent 086b3098b1
commit 7442323ca2
+12 -1
View File
@@ -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<boolean> {