mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 21:06:57 +00:00
parent
9fea64a934
commit
7464576c34
2 changed files with 45 additions and 5 deletions
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IEnvironmentVariableCollection, EnvironmentVariableMutatorType, IMergedEnvironmentVariableCollection, IMergedEnvironmentVariableCollectionDiff, IExtensionOwnedEnvironmentVariableMutator } from 'vs/workbench/contrib/terminal/common/environmentVariable';
|
||||
import { IProcessEnvironment } from 'vs/base/common/platform';
|
||||
import { IProcessEnvironment, isWindows } from 'vs/base/common/platform';
|
||||
|
||||
export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVariableCollection {
|
||||
readonly map: Map<string, IExtensionOwnedEnvironmentVariableMutator[]> = new Map();
|
||||
|
@ -42,17 +42,23 @@ export class MergedEnvironmentVariableCollection implements IMergedEnvironmentVa
|
|||
}
|
||||
|
||||
applyToProcessEnvironment(env: IProcessEnvironment): void {
|
||||
let lowerToActualVariableNames: { [lowerKey: string]: string | undefined } | undefined;
|
||||
if (isWindows) {
|
||||
lowerToActualVariableNames = {};
|
||||
Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e);
|
||||
}
|
||||
this.map.forEach((mutators, variable) => {
|
||||
const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable;
|
||||
mutators.forEach(mutator => {
|
||||
switch (mutator.type) {
|
||||
case EnvironmentVariableMutatorType.Append:
|
||||
env[variable] = (env[variable] || '') + mutator.value;
|
||||
env[actualVariable] = (env[actualVariable] || '') + mutator.value;
|
||||
break;
|
||||
case EnvironmentVariableMutatorType.Prepend:
|
||||
env[variable] = mutator.value + (env[variable] || '');
|
||||
env[actualVariable] = mutator.value + (env[actualVariable] || '');
|
||||
break;
|
||||
case EnvironmentVariableMutatorType.Replace:
|
||||
env[variable] = mutator.value;
|
||||
env[actualVariable] = mutator.value;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { deepStrictEqual, strictEqual } from 'assert';
|
||||
import { EnvironmentVariableMutatorType } from 'vs/workbench/contrib/terminal/common/environmentVariable';
|
||||
import { IProcessEnvironment } from 'vs/base/common/platform';
|
||||
import { IProcessEnvironment, isWindows } from 'vs/base/common/platform';
|
||||
import { MergedEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariableCollection';
|
||||
import { deserializeEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariableShared';
|
||||
|
||||
|
@ -119,6 +119,40 @@ suite('EnvironmentVariable - MergedEnvironmentVariableCollection', () => {
|
|||
C: 'c'
|
||||
});
|
||||
});
|
||||
|
||||
test('should apply to variable case insensitively on Windows only', () => {
|
||||
const merged = new MergedEnvironmentVariableCollection(new Map([
|
||||
['ext', {
|
||||
map: deserializeEnvironmentVariableCollection([
|
||||
['a', { value: 'a', type: EnvironmentVariableMutatorType.Replace }],
|
||||
['b', { value: 'b', type: EnvironmentVariableMutatorType.Append }],
|
||||
['c', { value: 'c', type: EnvironmentVariableMutatorType.Prepend }]
|
||||
])
|
||||
}]
|
||||
]));
|
||||
const env: IProcessEnvironment = {
|
||||
A: 'A',
|
||||
B: 'B',
|
||||
C: 'C'
|
||||
};
|
||||
merged.applyToProcessEnvironment(env);
|
||||
if (isWindows) {
|
||||
deepStrictEqual(env, {
|
||||
A: 'a',
|
||||
B: 'Bb',
|
||||
C: 'cC'
|
||||
});
|
||||
} else {
|
||||
deepStrictEqual(env, {
|
||||
a: 'a',
|
||||
A: 'A',
|
||||
b: 'b',
|
||||
B: 'B',
|
||||
c: 'c',
|
||||
C: 'C'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('diff', () => {
|
||||
|
|
Loading…
Reference in a new issue