(arg: string, shell: ShellType)
| 85 | * @returns The shell-escaped string. |
| 86 | */ |
| 87 | export function escapeShellArg(arg: string, shell: ShellType): string { |
| 88 | if (!arg) { |
| 89 | return ''; |
| 90 | } |
| 91 | |
| 92 | switch (shell) { |
| 93 | case 'powershell': |
| 94 | // For PowerShell, wrap in single quotes and escape internal single quotes by doubling them. |
| 95 | return `'${arg.replace(/'/g, "''")}'`; |
| 96 | case 'cmd': |
| 97 | // Simple Windows escaping for cmd.exe: wrap in double quotes and escape inner double quotes. |
| 98 | return `"${arg.replace(/"/g, '""')}"`; |
| 99 | case 'bash': |
| 100 | default: |
| 101 | // POSIX shell escaping using shell-quote. |
| 102 | return quote([arg]); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Splits a shell command into a list of individual commands, respecting quotes. |
no outgoing calls
no test coverage detected