Don't set en_US.UTF-8 on Windows when setLocale is false

Fixes #58015
This commit is contained in:
Daniel Imms
2018-09-19 12:28:40 -07:00
parent 67649d3923
commit dbdbbe5259
4 changed files with 16 additions and 7 deletions
@@ -392,7 +392,7 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
// Continue env initialization, merging in the env from the launch
// config and adding keys that are needed to create the process
const locale = terminalConfig.get('setLocaleVariables') ? platform.locale : undefined;
terminalEnvironment.addTerminalEnvironmentKeys(env, locale);
terminalEnvironment.addTerminalEnvironmentKeys(env, platform.isWindows, locale);
// Fork the process and listen for messages
this._logService.debug(`Terminal process launching on ext host`, shellLaunchConfig, initialCwd, cols, rows, env);
@@ -117,7 +117,7 @@ export class TerminalProcessManager implements ITerminalProcessManager {
// Adding other env keys necessary to create the process
const locale = this._configHelper.config.setLocaleVariables ? platform.locale : undefined;
terminalEnvironment.addTerminalEnvironmentKeys(env, locale);
terminalEnvironment.addTerminalEnvironmentKeys(env, platform.isWindows, locale);
this._logService.debug(`Terminal process launching`, shellLaunchConfig, this.initialCwd, cols, rows, env);
this._process = new TerminalProcess(shellLaunchConfig, this.initialCwd, cols, rows, env);
@@ -82,9 +82,14 @@ export function sanitizeEnvironment(env: platform.IProcessEnvironment): void {
});
}
export function addTerminalEnvironmentKeys(env: platform.IProcessEnvironment, locale: string | undefined): void {
export function addTerminalEnvironmentKeys(env: platform.IProcessEnvironment, isWindows: boolean, locale?: string): void {
env['TERM_PROGRAM'] = 'vscode';
env['TERM_PROGRAM_VERSION'] = pkg.version;
// Don't set $LANG if OS is Windows and the setLocale setting is false
if (isWindows && !locale) {
return;
}
env['LANG'] = _getLangEnvVariable(locale);
}
@@ -97,7 +102,7 @@ export function resolveConfigurationVariables(configurationResolverService: ICon
return env;
}
function _getLangEnvVariable(locale?: string) {
function _getLangEnvVariable(locale?: string): string {
const parts = locale ? locale.split('-') : [];
const n = parts.length;
if (n === 0) {
@@ -15,18 +15,22 @@ suite('Workbench - TerminalEnvironment', () => {
test('addTerminalEnvironmentKeys', () => {
const env = { FOO: 'bar' };
const locale = 'en-au';
terminalEnvironment.addTerminalEnvironmentKeys(env, locale);
terminalEnvironment.addTerminalEnvironmentKeys(env, false, locale);
assert.equal(env['TERM_PROGRAM'], 'vscode');
assert.equal(env['TERM_PROGRAM_VERSION'].search(/^\d+\.\d+\.\d+$/), 0);
assert.equal(env['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
const env2 = { FOO: 'bar' };
terminalEnvironment.addTerminalEnvironmentKeys(env2, null);
terminalEnvironment.addTerminalEnvironmentKeys(env2, false);
assert.equal(env2['LANG'], 'en_US.UTF-8', 'LANG is equal to en_US.UTF-8 as fallback.'); // More info on issue #14586
const env3 = { LANG: 'en_US.UTF-8' };
terminalEnvironment.addTerminalEnvironmentKeys(env3, null);
terminalEnvironment.addTerminalEnvironmentKeys(env3, false);
assert.equal(env3['LANG'], 'en_US.UTF-8', 'LANG is equal to the parent environment\'s LANG');
const env4 = {};
terminalEnvironment.addTerminalEnvironmentKeys(env4, true);
assert.equal(env4['LANG'], undefined, 'LANG is not set when the OS is Windows and the setLocale is false');
});
test('sanitizeEnvironment', () => {