diff --git a/src/features/execution/execUtils.ts b/src/features/execution/execUtils.ts index 49409ef7..b5f4671a 100644 --- a/src/features/execution/execUtils.ts +++ b/src/features/execution/execUtils.ts @@ -1,8 +1,14 @@ export function quoteStringIfNecessary(arg: string): string { - if (arg.indexOf(' ') >= 0 && !(arg.startsWith('"') && arg.endsWith('"'))) { - return `"${arg}"`; + // Always return if already quoted to avoid double-quoting + if (arg.startsWith('"') && arg.endsWith('"')) { + return arg; } - return arg; + + // Quote if contains common shell special characters that are problematic across multiple shells + // Includes: space, &, |, <, >, ;, ', ", `, (, ), [, ], {, }, $ + const needsQuoting = /[\s&|<>;'"`()\[\]{}$]/.test(arg); + + return needsQuoting ? `"${arg}"` : arg; } export function quoteArgs(args: string[]): string[] {