MCPcopy Index your code
hub / github.com/anus-dev/ANUS / escapeShellArg

Function escapeShellArg

packages/core/src/utils/shell-utils.ts:87–104  ·  view source on GitHub ↗
(arg: string, shell: ShellType)

Source from the content-addressed store, hash-verified

85 * @returns The shell-escaped string.
86 */
87export 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.

Callers 2

processMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected