Skip to content

Do not assume casing of activated environment variables Python returns #21970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
traceVerbose('Activating environments in terminal is disabled for', resource?.fsPath);
return;
}
const env = await this.environmentActivationService.getActivatedEnvironmentVariables(
const activatedEnv = await this.environmentActivationService.getActivatedEnvironmentVariables(
resource,
undefined,
undefined,
shell,
);
const env = activatedEnv ? normCaseKeys(activatedEnv) : undefined;
if (!env) {
const shellType = identifyShellFromShellPath(shell);
const defaultShell = defaultShells[this.platform.osType];
Expand All @@ -158,7 +159,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
shell,
);
}
const processEnv = this.processEnvVars;
const processEnv = normCaseKeys(this.processEnvVars);

// PS1 in some cases is a shell variable (not an env variable) so "env" might not contain it, calculate it in that case.
env.PS1 = await this.getPS1(shell, resource, env);
Expand Down Expand Up @@ -376,3 +377,11 @@ function getPromptForEnv(interpreter: PythonEnvironment | undefined) {
}
return undefined;
}

function normCaseKeys(env: EnvironmentVariables): EnvironmentVariables {
const result: EnvironmentVariables = {};
Object.keys(env).forEach((key) => {
result[key.toUpperCase()] = env[key];
});
return result;
}