Skip to content

Commit ad451bb

Browse files
authored
Resolve empty array environment variables microsoft#2532 (microsoft#2534)
1 parent 83be111 commit ad451bb

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

Extension/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# C/C++ for Visual Studio Code Change Log
22

3+
## Version 0.19.0: September 26, 2018
4+
* Add support for v2 of the configuration provider API. [#2237](https://github.com/Microsoft/vscode-cpptools/issues/2237)
5+
* Add `C_Cpp.updateChannel` setting for easier access to Insider builds of the extension. [#1526](https://github.com/Microsoft/vscode-cpptools/issues/1526)
6+
* Fix bug with variable resolution. [#2532](https://github.com/Microsoft/vscode-cpptools/issues/2532)
7+
38
## Version 0.18.1: August 17, 2018
49
* Fix 0.18.0 regression causing non-MinGW compilers to use `-fms-extensions` on Windows. [#2424](https://github.com/Microsoft/vscode-cpptools/issues/2424), [#2425](https://github.com/Microsoft/vscode-cpptools/issues/2425)
510

Extension/src/common.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,19 @@ export function isUri(input: any): input is vscode.Uri {
176176
}
177177

178178
export function isString(input: any): input is string {
179-
return input && typeof(input) === "string";
179+
return typeof(input) === "string";
180180
}
181181

182182
export function isOptionalString(input: any): input is string|undefined {
183-
return input === undefined || typeof(input) === "string";
183+
return input === undefined || isString(input);
184184
}
185185

186186
export function isArrayOfString(input: any): input is string[] {
187-
return input && (input instanceof Array) && input.every(item => typeof(item) === "string");
187+
return (input instanceof Array) && input.every(item => isString(item));
188188
}
189189

190190
export function isOptionalArrayOfString(input: any): input is string[]|undefined {
191-
return input === undefined || ((input instanceof Array) && input.every(item => typeof(item) === "string"));
191+
return input === undefined || isArrayOfString(input);
192192
}
193193

194194
export function resolveVariables(input: string, additionalEnvironment: {[key: string]: string | string[]}): string {
@@ -211,7 +211,7 @@ export function resolveVariables(input: string, additionalEnvironment: {[key: st
211211
if (varType === undefined) {
212212
varType = "env";
213213
}
214-
let newValue: string = undefined;
214+
let newValue: string;
215215
switch (varType) {
216216
case "env": {
217217
let v: string | string[] = additionalEnvironment[name];
@@ -220,7 +220,7 @@ export function resolveVariables(input: string, additionalEnvironment: {[key: st
220220
} else if (input === match && isArrayOfString(v)) {
221221
newValue = v.join(";");
222222
}
223-
if (!newValue) {
223+
if (!isString(newValue)) {
224224
newValue = process.env[name];
225225
}
226226
break;
@@ -246,7 +246,7 @@ export function resolveVariables(input: string, additionalEnvironment: {[key: st
246246
}
247247
default: { assert.fail("unknown varType matched"); }
248248
}
249-
return (newValue) ? newValue : match;
249+
return (isString(newValue)) ? newValue : match;
250250
});
251251
}
252252

Extension/test/unitTests/common.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ suite("Common Utility validation", () => {
3636
.shouldResolveTo("foo;bar");
3737
});
3838

39+
test("solo env input with empty array env value", () => {
40+
resolveVariablesWithInput("${empty}")
41+
.withEnvironment({
42+
"empty": []
43+
})
44+
.shouldResolveTo("");
45+
});
46+
3947
test("mixed raw and env input resulting in array", () => {
4048
const input: string = "baz${test}";
4149
resolveVariablesWithInput(input)

0 commit comments

Comments
 (0)