Skip to content

Commit e26c4bc

Browse files
authored
sanitize process env for external terminals on linux/mac (microsoft#128501)
1 parent 8523221 commit e26c4bc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/vs/platform/externalTerminal/node/externalTerminalService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ export class MacExternalTerminalService extends ExternalTerminalService implemen
144144
}
145145

146146
if (envVars) {
147-
for (let key in envVars) {
148-
const value = envVars[key];
147+
// merge environment variables into a copy of the process.env
148+
const env = Object.assign({}, getSanitizedEnvironment(process), envVars);
149+
150+
for (let key in env) {
151+
const value = env[key];
149152
if (value === null) {
150153
osaArgs.push('-u');
151154
osaArgs.push(key);
@@ -190,7 +193,8 @@ export class MacExternalTerminalService extends ExternalTerminalService implemen
190193
if (cwd) {
191194
args.push(cwd);
192195
}
193-
const child = spawner.spawn('/usr/bin/open', args);
196+
const env = getSanitizedEnvironment(process);
197+
const child = spawner.spawn('/usr/bin/open', args, { cwd, env });
194198
child.on('error', e);
195199
child.on('exit', () => c());
196200
});
@@ -226,8 +230,9 @@ export class LinuxExternalTerminalService extends ExternalTerminalService implem
226230
const bashCommand = `${quote(args)}; echo; read -p "${LinuxExternalTerminalService.WAIT_MESSAGE}" -n1;`;
227231
termArgs.push(`''${bashCommand}''`); // wrapping argument in two sets of ' because node is so "friendly" that it removes one set...
228232

233+
229234
// merge environment variables into a copy of the process.env
230-
const env = Object.assign({}, process.env, envVars);
235+
const env = Object.assign({}, getSanitizedEnvironment(process), envVars);
231236

232237
// delete environment variables that have a null value
233238
Object.keys(env).filter(v => env[v] === null).forEach(key => delete env[key]);

0 commit comments

Comments
 (0)