Skip to content

Commit

Permalink
Quote args for bash, fixes #61056
Browse files Browse the repository at this point in the history
The TerminalLauncher does not properly escape arguments for the Bash
shell. This change wraps all arguments in single-quotes, and escapes the
single quote. This means that bash special characters in arguments will not be
evaluated.
  • Loading branch information
Brcrwilliams committed Oct 20, 2018
1 parent 499c7c7 commit 6d07235
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/vs/workbench/parts/debug/node/terminals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
case ShellType.bash:

quote = (s: string) => {
s = s.replace(/\"/g, '\\"');
return (s.indexOf(' ') >= 0 || s.indexOf('\\') >= 0) ? `"${s}"` : s;
s = s.replace(/'/g, '\'\\\'\'');
return `'${s}'`;
};

if (args.cwd) {
Expand All @@ -400,9 +400,9 @@ export function prepareCommand(args: DebugProtocol.RunInTerminalRequestArguments
for (let key in args.env) {
const value = args.env[key];
if (value === null) {
command += ` -u "${key}"`;
command += ` -u ${quote(key)}`;
} else {
command += ` "${key}=${value}"`;
command += ` ${quote(`${key}=${value}`)}`;
}
}
command += ' ';
Expand Down

0 comments on commit 6d07235

Please sign in to comment.