More accurate escaping and quoting for debug commands in terminal. Fix #145265

This commit is contained in:
Rob Lourens
2022-04-11 20:25:17 -07:00
parent b0c5a282e5
commit fcaeb69ec8
@@ -121,7 +121,7 @@ export function prepareCommand(shell: string, args: string[], cwd?: string, env?
quote = (s: string) => {
s = s.replace(/\"/g, '""');
return (s.indexOf(' ') >= 0 || s.indexOf('"') >= 0 || s.length === 0) ? `"${s}"` : s;
return (' "><!^&'.split('').some(char => s.includes(char)) || s.length === 0) ? `"${s}"` : s;
};
if (cwd) {
@@ -154,8 +154,8 @@ export function prepareCommand(shell: string, args: string[], cwd?: string, env?
case ShellType.bash: {
quote = (s: string) => {
s = s.replace(/(["'\\\$])/g, '\\$1');
return (s.indexOf(' ') >= 0 || s.indexOf(';') >= 0 || s.length === 0) ? `"${s}"` : s;
s = s.replace(/(["'\\\$!><#()\[\]*&^])/g, '\\$1');
return (' ;'.split('').some(char => s.includes(char)) || s.length === 0) ? `"${s}"` : s;
};
const hardQuote = (s: string) => {