forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecUtils.ts
More file actions
21 lines (17 loc) · 729 Bytes
/
execUtils.ts
File metadata and controls
21 lines (17 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export function quoteStringIfNecessary(arg: string): string {
// Always return if already quoted to avoid double-quoting
if (arg.startsWith('"') && arg.endsWith('"')) {
return arg;
}
// Don't quote single shell operators/special characters
if (arg.length === 1 && /[&|<>;()[\]{}$]/.test(arg)) {
return arg;
}
// Quote if contains common shell special characters that are problematic across multiple shells
// Includes: space, &, |, <, >, ;, ', ", `, (, ), [, ], {, }, $
const needsQuoting = /[\s&|<>;'"`()\[\]{}$]/.test(arg);
return needsQuoting ? `"${arg}"` : arg;
}
export function quoteArgs(args: string[]): string[] {
return args.map(quoteStringIfNecessary);
}