Also escape pipe character in bash shell. #145265

This commit is contained in:
Rob Lourens 2022-04-20 11:08:51 -07:00
parent 87191b089d
commit d7dbb0b8a2

View file

@ -121,7 +121,7 @@ export function prepareCommand(shell: string, args: string[], cwd?: string, env?
quote = (s: string) => {
s = s.replace(/\"/g, '""');
s = s.replace(/([><!^&\|])/g, '^$1');
s = s.replace(/([><!^&|])/g, '^$1');
return (' "'.split('').some(char => s.includes(char)) || s.length === 0) ? `"${s}"` : s;
};
@ -139,7 +139,7 @@ export function prepareCommand(shell: string, args: string[], cwd?: string, env?
if (value === null) {
command += `set "${key}=" && `;
} else {
value = value.replace(/[\^\&\|\<\>]/g, s => `^${s}`);
value = value.replace(/[^&|<>]/g, s => `^${s}`);
command += `set "${key}=${value}" && `;
}
}
@ -155,7 +155,7 @@ export function prepareCommand(shell: string, args: string[], cwd?: string, env?
case ShellType.bash: {
quote = (s: string) => {
s = s.replace(/(["'\\\$!><#()\[\]*&^])/g, '\\$1');
s = s.replace(/(["'\\\$!><#()\[\]*&^|])/g, '\\$1');
return (' ;'.split('').some(char => s.includes(char)) || s.length === 0) ? `"${s}"` : s;
};