Skip to content

Commit 11fce0e

Browse files
committed
🤖 fix: properly escape single quotes in SSH command for Terminal.app
Fixes P1 issue where nested single quotes in the remote command would break Terminal.app's AppleScript parsing. Now uses proper shell escaping: 'foo'\''bar' Generated with `cmux`
1 parent ebca93b commit 11fce0e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/services/ipcMain.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,16 @@ export class IpcMain {
13431343
let args: string[];
13441344
if (isSSH && sshArgs) {
13451345
// Terminal.app: Use osascript to run ssh command
1346-
const sshCommand = `ssh ${sshArgs.map((arg) => (arg.includes(" ") ? `'${arg}'` : arg)).join(" ")}`;
1346+
// Properly escape single quotes in args before wrapping in quotes
1347+
const sshCommand = `ssh ${sshArgs
1348+
.map((arg) => {
1349+
if (arg.includes(" ") || arg.includes("'")) {
1350+
// Escape single quotes by ending quote, adding escaped quote, starting quote again
1351+
return `'${arg.replace(/'/g, "'\\''")}'`;
1352+
}
1353+
return arg;
1354+
})
1355+
.join(" ")}`;
13471356
const script = `tell application "Terminal" to do script "${sshCommand.replace(/"/g, '\\"')}"`;
13481357
args = ["-e", script];
13491358
} else {

0 commit comments

Comments
 (0)