Skip to content

Commit 45e8ec1

Browse files
committed
🤖 fix: have bash decode base64 to avoid all quoting issues
The previous approach had PowerShell decode base64 then pass to bash -c, but the decoded script contained double quotes that conflicted with the outer quoting. New approach: pass base64 string directly to bash which decodes it: wsl bash -c 'echo BASE64 | base64 -d | bash' This works because: 1. Base64 only contains [A-Za-z0-9+/=] - no special chars 2. The decode happens inside bash, so no quoting issues 3. Single quotes pass the string literally through PowerShell to WSL
1 parent c0fde48 commit 45e8ec1

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/node/utils/main/bashPath.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,15 @@ export function getSpawnConfig(runtime: BashRuntime, script: string, cwd?: strin
390390
const psPath = getPowerShellPath();
391391
if (psPath) {
392392
// Base64 encode the script to avoid any PowerShell parsing issues
393-
// PowerShell will decode it and pass to WSL bash -c
394393
const base64Script = Buffer.from(fullScript, "utf8").toString("base64");
395394

396-
// Build the PowerShell command that:
397-
// 1. Decodes the base64 script into variable $s
398-
// 2. Passes $s to WSL bash -c with proper quoting
395+
// Pass the base64 string directly to bash, which decodes and executes it.
396+
// This completely avoids quoting issues because:
397+
// 1. Base64 only contains [A-Za-z0-9+/=] - no special chars
398+
// 2. The decode happens inside bash, so PowerShell never sees the script
399+
// 3. Single quotes in PowerShell pass the string literally to WSL
399400
const wslArgs = runtime.distro ? `-d ${runtime.distro}` : "";
400-
// CRITICAL: Must quote $s with escaped double quotes (`"$s`") so the entire
401-
// script is passed as a single argument to bash -c. Without quotes, PowerShell
402-
// expands $s and bash only sees the first word as the -c argument.
403-
const psCommand =
404-
`$s=[System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${base64Script}'));` +
405-
`wsl ${wslArgs} bash -c \`"$s\`"`.trim();
401+
const psCommand = `wsl ${wslArgs} bash -c 'echo ${base64Script} | base64 -d | bash'`.trim();
406402

407403
return {
408404
command: psPath,

0 commit comments

Comments
 (0)