Skip to content
Open
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
25 changes: 24 additions & 1 deletion src/spec-common/variableSubstitution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function replaceWithContext(isWindows: boolean, context: SubstitutionContext, ma
case 'localEnv':
return lookupValue(isWindows, context.env, args, match, context.configFile);

case 'localHomeFolder':
return lookupHomeFolder(isWindows, context.env, args, match, context.configFile);

case 'localWorkspaceFolder':
return context.localWorkspaceFolder !== undefined ? context.localWorkspaceFolder : match;

Expand Down Expand Up @@ -134,6 +137,26 @@ function replaceDevContainerId(getDevContainerId: () => string | undefined, matc
}
}

function lookupHomeFolder(isWindows: boolean, envObj: NodeJS.ProcessEnv, args: string[], match: string, configFile: URI | undefined) {
if (args.length != 0) {
let envVariableName = "HOME";
if (isWindows) {
envVariableName = "userprofile";
}
const env = envObj[envVariableName];
if (typeof env === 'string') {
return env;
}

// For `env` we should do the same as a normal shell does - evaluates missing envs to an empty string #46436
return '';
}
throw new ContainerError({
description: `'${match}'${configFile ? ` in ${path.posix.basename(configFile.path)}` : ''} localHomeFolder cannot have any arguments.`
});
}


function lookupValue(isWindows: boolean, envObj: NodeJS.ProcessEnv, args: string[], match: string, configFile: URI | undefined) {
if (args.length > 0) {
let envVariableName = args[0];
Expand Down Expand Up @@ -168,4 +191,4 @@ function devcontainerIdForLabels(idLabels: Record<string, string>): string {
.toString(32)
.padStart(52, '0');
return uniqueId;
}
}