diff --git a/src/spec-common/variableSubstitution.ts b/src/spec-common/variableSubstitution.ts index d973f0cd6..272e5c4a0 100644 --- a/src/spec-common/variableSubstitution.ts +++ b/src/spec-common/variableSubstitution.ts @@ -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; @@ -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]; @@ -168,4 +191,4 @@ function devcontainerIdForLabels(idLabels: Record): string { .toString(32) .padStart(52, '0'); return uniqueId; -} \ No newline at end of file +}