Skip to content

Commit a9b4f0d

Browse files
Kartik Rajeleanorjboyd
Kartik Raj
authored andcommitted
Make sure PATH ends with a separator before prepending (microsoft#22046)
Introduced with microsoft#21906 For microsoft#20950 Fixes microsoft#22047
1 parent d917b9c commit a9b4f0d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/client/interpreter/activation/terminalEnvVarCollectionService.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
6363
*/
6464
private processEnvVars: EnvironmentVariables | undefined;
6565

66+
private separator: string;
67+
6668
constructor(
6769
@inject(IPlatformService) private readonly platform: IPlatformService,
6870
@inject(IInterpreterService) private interpreterService: IInterpreterService,
@@ -75,7 +77,9 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
7577
@inject(IWorkspaceService) private workspaceService: IWorkspaceService,
7678
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
7779
@inject(IPathUtils) private readonly pathUtils: IPathUtils,
78-
) {}
80+
) {
81+
this.separator = platform.osType === OSType.Windows ? ';' : ':';
82+
}
7983

8084
public async activate(resource: Resource): Promise<void> {
8185
try {
@@ -196,6 +200,9 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
196200
applyAtProcessCreation: true,
197201
});
198202
} else {
203+
if (!value.endsWith(this.separator)) {
204+
value = value.concat(this.separator);
205+
}
199206
traceVerbose(`Prepending environment variable ${key} in collection to ${value}`);
200207
envVarCollection.prepend(key, value, {
201208
applyAtShellIntegration: true,

src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ suite('Terminal Environment Variable Collection Service', () => {
248248
assert.deepEqual(opts, { applyAtProcessCreation: true, applyAtShellIntegration: true });
249249
});
250250

251-
test('Prepend full PATH otherwise', async () => {
251+
test('Prepend full PATH with separator otherwise', async () => {
252252
const processEnv = { PATH: 'hello/1/2/3' };
253253
reset(environmentActivationService);
254254
when(environmentActivationService.getProcessEnvironmentVariables(anything(), anything())).thenResolve(
255255
processEnv,
256256
);
257+
const separator = getOSType() === OSType.Windows ? ';' : ':';
257258
const finalPath = 'hello/3/2/1';
258259
const envVars: NodeJS.ProcessEnv = { PATH: finalPath };
259260
when(
@@ -275,7 +276,7 @@ suite('Terminal Environment Variable Collection Service', () => {
275276
await terminalEnvVarCollectionService._applyCollection(undefined, customShell);
276277

277278
verify(collection.clear()).once();
278-
verify(collection.prepend('PATH', finalPath, anything())).once();
279+
verify(collection.prepend('PATH', `${finalPath}${separator}`, anything())).once();
279280
verify(collection.replace('PATH', anything(), anything())).never();
280281
assert.deepEqual(opts, { applyAtProcessCreation: true, applyAtShellIntegration: true });
281282
});

0 commit comments

Comments
 (0)