From b6c0360f825c6f5dd11be04b4087a0a52d51a250 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 2 Mar 2022 14:00:55 -0800 Subject: Evaluate standalone variables for truthiness in the preprocessor Fixes 4770 --- src/wix/WixToolset.Core/Preprocessor.cs | 4 +- .../WixToolsetTest.Core/PreprocessorFixture.cs | 46 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/wix/WixToolset.Core/Preprocessor.cs b/src/wix/WixToolset.Core/Preprocessor.cs index 3abe0b5f..084da8d0 100644 --- a/src/wix/WixToolset.Core/Preprocessor.cs +++ b/src/wix/WixToolset.Core/Preprocessor.cs @@ -1089,10 +1089,10 @@ namespace WixToolset.Core else if (operation.Length == 0) { // There is no right side of the equation. - // If the variable was evaluated, it exists, so the expression is true + // If the variable was evaluated, test to see if it is a "false" value. if (startsWithVariable) { - expressionValue = true; + expressionValue = !(leftValue == String.Empty || leftValue == "0" || leftValue == "false" || leftValue == "no"); } else { diff --git a/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs b/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs index b3ad0803..bbae4636 100644 --- a/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs +++ b/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs @@ -61,6 +61,52 @@ namespace WixToolsetTest.Core WixAssert.CompareLineByLine(expected, actual); } + [Fact] + public void CanPreprocessFalsyCondition() + { + var input = String.Join(Environment.NewLine, + "", + "", + "", + " ", + "", + "" + ); + var expected = new[] + { + "" + }; + + var result = PreprocessFromString(input); + + var actual = result.Document.ToString().Split("\r\n"); + WixAssert.CompareLineByLine(expected, actual); + } + + [Fact] + public void CanPreprocessTruthyCondition() + { + var input = String.Join(Environment.NewLine, + "", + "", + "", + " ", + "", + "" + ); + var expected = new[] + { + "", + " ", + "" + }; + + var result = PreprocessFromString(input); + + var actual = result.Document.ToString().Split("\r\n"); + WixAssert.CompareLineByLine(expected, actual); + } + private static IPreprocessResult PreprocessFromString(string xml) { using var stringReader = new StringReader(xml); -- cgit v1.2.3-55-g6feb