Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,12 @@ export function resolveVariables(input: string | undefined, additionalEnvironmen
const cycleCache = new Set<string>();
while (!cycleCache.has(ret)) {
cycleCache.add(ret);
ret = ret.replace(regexp(), (match: string, ignored1: string, varType: string, ignored2: string, name: string) => {
// Historically, if the variable didn't have anything before the "." or ":"
// it was assumed to be an environment variable
if (!varType) {
varType = "env";
}
ret = ret.replace(regexp(), (match: string, ignored1: string | undefined, varType: string | undefined, ignored2: string | undefined, name: string) => {
let newValue: string | undefined;
switch (varType) {
// Historically, if the variable didn't have anything before the "." or ":"
// it was assumed to be an environment variable
case undefined:
case "env": {
if (additionalEnvironment) {
const v: string | string[] | undefined = additionalEnvironment[name];
Expand All @@ -425,6 +423,12 @@ export function resolveVariables(input: string | undefined, additionalEnvironmen
if (newValue === undefined) {
newValue = process.env[name];
}

// If the environment variable is not set, we return an empty string. Only do
// this for ${env:X} variables, not ${X} variables.
if (newValue === undefined && varType !== undefined) {
newValue = "";
}
break;
}
case "config": {
Expand Down
17 changes: 17 additions & 0 deletions Extension/test/scenarios/SingleRootProject/tests/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ suite("resolveVariables", () => {
.shouldLookupSymbol("Root");
});

test("${env:X} expands to empty when unset", () => {
const processKey: string = `cpptoolstests_unset_${Date.now()}`;
delete process.env[processKey];
resolveVariablesWithInput("${env:" + processKey + "}")
.withEnvironment({})
.shouldResolveTo("");
});

test("${X} left unexpanded when unset", () => {
const processKey: string = `cpptoolstests_unset_${Date.now()}`;
delete process.env[processKey];
const token: string = "${" + processKey + "}";
resolveVariablesWithInput(token)
.withEnvironment({})
.shouldResolveTo(token);
});

test("escapeForSquiggles:", () => {
const testEscapeForSquigglesScenario: any = (input: string, expectedOutput: string) => {
const result: string = escapeForSquiggles(input);
Expand Down
Loading