Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit a3b2a9b

Browse files
committed
escapeArguement. Fixes #386, fixes #358.
1 parent 3d2ec37 commit a3b2a9b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: src/PTY.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@ const noConfigSwitches: Dictionary<string[]> = {
99
bash: ["--noprofile", "--norc"],
1010
};
1111

12+
function escapeArgument(argument: string) {
13+
if (argument.includes('"') || argument.includes(" ")) {
14+
return `'${argument}'`;
15+
} else if (argument.includes("'")) {
16+
return `"${argument}"`;
17+
} else {
18+
return argument;
19+
}
20+
}
21+
1222
export default class PTY {
1323
private terminal: pty.Terminal;
1424

1525
// TODO: write proper signatures.
1626
// TODO: use generators.
1727
// TODO: terminate. https://github.com/atom/atom/blob/v1.0.15/src/task.coffee#L151
1828
constructor(command: string, args: string[], env: ProcessEnvironment, dimensions: Dimensions, dataHandler: (d: string) => void, exitHandler: (c: number) => void) {
19-
this.terminal = pty.fork(shell(), [...noConfigSwitches[baseName(shell())], "-c", `${command} ${args.map(arg => `'${arg}'`).join(" ")}`], {
29+
this.terminal = pty.fork(shell(), [...noConfigSwitches[baseName(shell())], "-c", `${command} ${args.map(escapeArgument).join(" ")}`], {
2030
cols: dimensions.columns,
2131
rows: dimensions.rows,
2232
cwd: env.PWD,

0 commit comments

Comments
 (0)