Support environment variables with parens in the preprocessor
Fixes wixtoolset/issues#4484
Rob Mensching committed
Jan 7, 2021 at 15:12 UTC
a36c59a4911a7db525f6b03dc98fac5adde163b4
3 files changed
+30
src/WixToolset.Core/ExtensibilityServices/PreprocessHelper.cs
+8
@@ -386,6 +386,14 @@ namespace WixToolset.Core.ExtensibilityServices
386
}
387
}
388
389
+ // Environment variables may contain parens so if it looks
390
+ // like a function, check to see if the environment variable
391
+ // prefix was explicitly provided.
392
+ if (isFunction && remainder.StartsWith("(env.", StringComparison.Ordinal))
393
+ {
394
+ isFunction = false;
395
+ }
396
+
397
// move the currentPosition to the closing paren
398
currentPosition += closingParenPosition;
399
src/test/WixToolsetTest.CoreIntegration/PreprocessorFixture.cs
+18
@@ -39,6 +39,24 @@ namespace WixToolsetTest.CoreIntegration
39
Assert.Null(includedFile.SourceLineNumbers.Parent);
40
}
41
42
+ [Fact]
43
+ /// <remarks>
44
+ /// This test will fail on 32-bit operating systems because it depends on "CommonProgramFiles(x86)"
45
+ /// which is only defined on 64-bit Windows.
46
+ /// </remarks>
47
+ public void SupportParensInEnvironmentVariables()
48
+ {
49
+ var folder = TestData.Get(@"TestData", "Preprocessor");
50
+
51
+ var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
52
+ var context = serviceProvider.GetService<IPreprocessContext>();
53
+ context.SourcePath = Path.Combine(folder, "EnvParens.wxs");
54
+
55
+ var preprocessor = serviceProvider.GetService<IPreprocessor>();
56
+ var result = preprocessor.Preprocess(context);
57
+ Assert.NotNull(result.Document);
58
+ }
59
+
60
[Fact]
61
public void VariableRedefinitionIsAWarning()
62
{
src/test/WixToolsetTest.CoreIntegration/TestData/Preprocessor/EnvParens.wxs
new
+4
@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="utf-8" ?>
2
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3
+ <?define Test = "$(env.CommonProgramFiles(x86))" ?>
4
+</Wix>