mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 06:18:55 +00:00
fix(doctor): use cmd.exe compatible quoting for Windows shell execution
The escapeShellArg function was using PowerShell-style single quotes,
but spawn({ shell: true }) uses cmd.exe by default on Windows.
cmd.exe does not recognize single quotes as string delimiters,
causing 'claude' '--version' to fail.
Changed to use double quotes which work correctly in cmd.exe.
This commit is contained in:
@@ -9,33 +9,22 @@ import { ErrorManager } from './error-manager';
|
|||||||
import { getWebSearchHookEnv } from './websearch-manager';
|
import { getWebSearchHookEnv } from './websearch-manager';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape arguments for shell execution (Windows compatibility)
|
* Escape arguments for shell execution (cross-platform)
|
||||||
* Handles PowerShell special characters: backticks, $variables, double quotes
|
*
|
||||||
|
* IMPORTANT: On Windows, spawn({ shell: true }) uses cmd.exe by default,
|
||||||
|
* NOT PowerShell. cmd.exe does NOT recognize single quotes as string delimiters.
|
||||||
|
* We must use double quotes for cmd.exe compatibility.
|
||||||
*/
|
*/
|
||||||
export function escapeShellArg(arg: string): string {
|
export function escapeShellArg(arg: string): string {
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
|
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
// PowerShell: Use single quotes for literal strings to prevent variable expansion
|
// cmd.exe: Use double quotes, escape inner double quotes with backslash
|
||||||
// Escape single quotes by doubling them (PowerShell syntax)
|
// cmd.exe interprets "" as escaped double quote inside quoted string
|
||||||
// Fallback to double quotes with escapes if single quotes present
|
return '"' + String(arg).replace(/"/g, '""') + '"';
|
||||||
if (arg.includes("'")) {
|
|
||||||
// Contains single quote - use double quotes with escape sequences
|
|
||||||
return (
|
|
||||||
'"' +
|
|
||||||
String(arg)
|
|
||||||
.replace(/\$/g, '`$') // Escape $ to prevent variable expansion
|
|
||||||
.replace(/`/g, '``') // Escape backticks
|
|
||||||
.replace(/"/g, '`"') + // Escape double quotes
|
|
||||||
'"'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// No single quotes - use single quotes for literal string (safest)
|
|
||||||
return "'" + String(arg) + "'";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Unix/macOS: Double quotes with escaped inner quotes
|
// Unix/macOS: Double quotes with escaped inner quotes
|
||||||
return '"' + String(arg).replace(/"/g, '""') + '"';
|
return '"' + String(arg).replace(/"/g, '\\"') + '"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user