don't wrap args unnecessarily (#26599)

This commit is contained in:
Tommaso Sciortino
2026-05-06 16:20:47 -07:00
committed by GitHub
parent 90304b279c
commit a809bc7c51
3 changed files with 20 additions and 6 deletions
+9 -1
View File
@@ -695,9 +695,17 @@ export function escapeShellArg(arg: string, shell: ShellType): string {
switch (shell) {
case 'powershell':
// For PowerShell, wrap in single quotes and escape internal single quotes by doubling them.
// For PowerShell, avoid quoting simple alphanumeric strings (like UUIDs).
if (/^[a-zA-Z0-9\-_.]+$/.test(arg)) {
return arg;
}
// Otherwise, wrap in single quotes and escape internal single quotes by doubling them.
return `'${arg.replace(/'/g, "''")}'`;
case 'cmd':
// Avoid quoting simple strings for cmd.exe as well.
if (/^[a-zA-Z0-9\-_.]+$/.test(arg)) {
return arg;
}
// Simple Windows escaping for cmd.exe: wrap in double quotes and escape inner double quotes.
return `"${arg.replace(/"/g, '""')}"`;
case 'bash':