aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-03-02 13:57:05 -0800
committerRob Mensching <rob@firegiant.com>2022-03-02 14:38:30 -0800
commitf99cd1b1616909f0314504c9fdba836e162e1fa6 (patch)
treea1aa5054e2a51c4a673db3b9d7377427079e5155
parent558dd1a421d53ebb9ca3171bcccc39eb58dfec70 (diff)
downloadwix-f99cd1b1616909f0314504c9fdba836e162e1fa6.tar.gz
wix-f99cd1b1616909f0314504c9fdba836e162e1fa6.tar.bz2
wix-f99cd1b1616909f0314504c9fdba836e162e1fa6.zip
Support "==" as equality operator in preprocessor
Fixes 5880
-rw-r--r--src/wix/WixToolset.Core/Preprocessor.cs13
-rw-r--r--src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs79
-rw-r--r--src/wix/test/WixToolsetTest.Core/WixToolsetTest.Core.csproj25
-rw-r--r--src/wix/wix.sln19
4 files changed, 133 insertions, 3 deletions
diff --git a/src/wix/WixToolset.Core/Preprocessor.cs b/src/wix/WixToolset.Core/Preprocessor.cs
index 486a4c8c..3abe0b5f 100644
--- a/src/wix/WixToolset.Core/Preprocessor.cs
+++ b/src/wix/WixToolset.Core/Preprocessor.cs
@@ -185,6 +185,7 @@ namespace WixToolset.Core
185 } 185 }
186 186
187 if ("=" == operation || 187 if ("=" == operation ||
188 "==" == operation ||
188 "!=" == operation || 189 "!=" == operation ||
189 "<" == operation || 190 "<" == operation ||
190 "<=" == operation || 191 "<=" == operation ||
@@ -885,6 +886,7 @@ namespace WixToolset.Core
885 // or end of string, whichever comes first 886 // or end of string, whichever comes first
886 var space = expression.IndexOf(" ", StringComparison.Ordinal); 887 var space = expression.IndexOf(" ", StringComparison.Ordinal);
887 var equals = expression.IndexOf("=", StringComparison.Ordinal); 888 var equals = expression.IndexOf("=", StringComparison.Ordinal);
889 var doubleEquals = expression.IndexOf("==", StringComparison.Ordinal);
888 var lessThan = expression.IndexOf("<", StringComparison.Ordinal); 890 var lessThan = expression.IndexOf("<", StringComparison.Ordinal);
889 var lessThanEquals = expression.IndexOf("<=", StringComparison.Ordinal); 891 var lessThanEquals = expression.IndexOf("<=", StringComparison.Ordinal);
890 var greaterThan = expression.IndexOf(">", StringComparison.Ordinal); 892 var greaterThan = expression.IndexOf(">", StringComparison.Ordinal);
@@ -903,6 +905,11 @@ namespace WixToolset.Core
903 equals = Int32.MaxValue; 905 equals = Int32.MaxValue;
904 } 906 }
905 907
908 if (doubleEquals == -1)
909 {
910 doubleEquals = Int32.MaxValue;
911 }
912
906 if (lessThan == -1) 913 if (lessThan == -1)
907 { 914 {
908 lessThan = Int32.MaxValue; 915 lessThan = Int32.MaxValue;
@@ -933,7 +940,7 @@ namespace WixToolset.Core
933 equalsNoCase = Int32.MaxValue; 940 equalsNoCase = Int32.MaxValue;
934 } 941 }
935 942
936 closingIndex = Math.Min(space, Math.Min(equals, Math.Min(lessThan, Math.Min(lessThanEquals, Math.Min(greaterThan, Math.Min(greaterThanEquals, Math.Min(equalsNoCase, notEquals))))))); 943 closingIndex = Math.Min(space, Math.Min(equals, Math.Min(doubleEquals, Math.Min(lessThan, Math.Min(lessThanEquals, Math.Min(greaterThan, Math.Min(greaterThanEquals, Math.Min(equalsNoCase, notEquals))))))));
937 944
938 if (Int32.MaxValue == closingIndex) 945 if (Int32.MaxValue == closingIndex)
939 { 946 {
@@ -944,7 +951,7 @@ namespace WixToolset.Core
944 if (0 == closingIndex) 951 if (0 == closingIndex)
945 { 952 {
946 // Length 2 operators 953 // Length 2 operators
947 if (closingIndex == lessThanEquals || closingIndex == greaterThanEquals || closingIndex == notEquals || closingIndex == equalsNoCase) 954 if (closingIndex == doubleEquals || closingIndex == lessThanEquals || closingIndex == greaterThanEquals || closingIndex == notEquals || closingIndex == equalsNoCase)
948 { 955 {
949 closingIndex = 2; 956 closingIndex = 2;
950 } 957 }
@@ -1096,7 +1103,7 @@ namespace WixToolset.Core
1096 { 1103 {
1097 leftValue = leftValue.Trim(); 1104 leftValue = leftValue.Trim();
1098 rightValue = rightValue.Trim(); 1105 rightValue = rightValue.Trim();
1099 if ("=" == operation) 1106 if ("=" == operation || "==" == operation)
1100 { 1107 {
1101 if (leftValue == rightValue) 1108 if (leftValue == rightValue)
1102 { 1109 {
diff --git a/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs b/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs
new file mode 100644
index 00000000..b3ad0803
--- /dev/null
+++ b/src/wix/test/WixToolsetTest.Core/PreprocessorFixture.cs
@@ -0,0 +1,79 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolsetTest.Core
4{
5 using System;
6 using System.IO;
7 using System.Xml;
8 using WixBuildTools.TestSupport;
9 using WixToolset.Core;
10 using WixToolset.Extensibility.Data;
11 using WixToolset.Extensibility.Services;
12 using Xunit;
13
14 public class PreprocessorFixture
15 {
16 [Fact]
17 public void CanPreprocessWithSingleEquals()
18 {
19 var input = String.Join(Environment.NewLine,
20 "<Wix>",
21 "<?define A=0?>",
22 "<?if $(A)=\"0\" ?>",
23 " <Package />",
24 "<?endif?>",
25 "</Wix>"
26 );
27 var expected = new[]
28 {
29 "<Wix>",
30 " <Package />",
31 "</Wix>"
32 };
33
34 var result = PreprocessFromString(input);
35
36 var actual = result.Document.ToString().Split("\r\n");
37 WixAssert.CompareLineByLine(expected, actual);
38 }
39
40 [Fact]
41 public void CanPreprocessWithDoubleEquals()
42 {
43 var input = String.Join(Environment.NewLine,
44 "<Wix>",
45 "<?define A=0?>",
46 "<?if $(A)==\"0\" ?>",
47 " <Fragment />",
48 "<?endif?>",
49 "</Wix>"
50 );
51 var expected = new[]
52 {
53 "<Wix>",
54 " <Fragment />",
55 "</Wix>"
56 };
57
58 var result = PreprocessFromString(input);
59
60 var actual = result.Document.ToString().Split("\r\n");
61 WixAssert.CompareLineByLine(expected, actual);
62 }
63
64 private static IPreprocessResult PreprocessFromString(string xml)
65 {
66 using var stringReader = new StringReader(xml);
67 using var xmlReader = XmlReader.Create(stringReader);
68
69 var sp = WixToolsetServiceProviderFactory.CreateServiceProvider();
70
71 var context = sp.GetService<IPreprocessContext>();
72 context.SourcePath = @"path\provided\for\testing\purposes\only.wxs";
73
74 var preprocessor = context.ServiceProvider.GetService<IPreprocessor>();
75 var result = preprocessor.Preprocess(context, xmlReader);
76 return result;
77 }
78 }
79}
diff --git a/src/wix/test/WixToolsetTest.Core/WixToolsetTest.Core.csproj b/src/wix/test/WixToolsetTest.Core/WixToolsetTest.Core.csproj
new file mode 100644
index 00000000..3b0259cb
--- /dev/null
+++ b/src/wix/test/WixToolsetTest.Core/WixToolsetTest.Core.csproj
@@ -0,0 +1,25 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
4<Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netcoreapp3.1</TargetFramework>
7 <IsPackable>false</IsPackable>
8 <DebugType>embedded</DebugType>
9 <SignOutput>false</SignOutput>
10 </PropertyGroup>
11
12 <ItemGroup>
13 <ProjectReference Include="..\..\WixToolset.Core\WixToolset.Core.csproj" />
14 </ItemGroup>
15
16 <ItemGroup>
17 <PackageReference Include="WixBuildTools.TestSupport" />
18 </ItemGroup>
19
20 <ItemGroup>
21 <PackageReference Include="Microsoft.NET.Test.Sdk" />
22 <PackageReference Include="xunit" />
23 <PackageReference Include="xunit.runner.visualstudio" PrivateAssets="All" />
24 </ItemGroup>
25</Project>
diff --git a/src/wix/wix.sln b/src/wix/wix.sln
index 15ee82e4..81faf8be 100644
--- a/src/wix/wix.sln
+++ b/src/wix/wix.sln
@@ -52,6 +52,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.BuildTasks",
52EndProject 52EndProject
53Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "pack-wix", "pack-wix\pack-wix.csproj", "{CE489499-60E1-4883-B72A-CA8F95DBA073}" 53Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "pack-wix", "pack-wix\pack-wix.csproj", "{CE489499-60E1-4883-B72A-CA8F95DBA073}"
54EndProject 54EndProject
55Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.Core", "test\WixToolsetTest.Core\WixToolsetTest.Core.csproj", "{392817AE-4493-4BED-A7FD-2399379E1B1C}"
56EndProject
55Global 57Global
56 GlobalSection(SolutionConfigurationPlatforms) = preSolution 58 GlobalSection(SolutionConfigurationPlatforms) = preSolution
57 Debug|Any CPU = Debug|Any CPU 59 Debug|Any CPU = Debug|Any CPU
@@ -448,6 +450,22 @@ Global
448 {CE489499-60E1-4883-B72A-CA8F95DBA073}.Release|x64.Build.0 = Release|Any CPU 450 {CE489499-60E1-4883-B72A-CA8F95DBA073}.Release|x64.Build.0 = Release|Any CPU
449 {CE489499-60E1-4883-B72A-CA8F95DBA073}.Release|x86.ActiveCfg = Release|Any CPU 451 {CE489499-60E1-4883-B72A-CA8F95DBA073}.Release|x86.ActiveCfg = Release|Any CPU
450 {CE489499-60E1-4883-B72A-CA8F95DBA073}.Release|x86.Build.0 = Release|Any CPU 452 {CE489499-60E1-4883-B72A-CA8F95DBA073}.Release|x86.Build.0 = Release|Any CPU
453 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
454 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
455 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|ARM64.ActiveCfg = Debug|Any CPU
456 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|ARM64.Build.0 = Debug|Any CPU
457 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|x64.ActiveCfg = Debug|Any CPU
458 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|x64.Build.0 = Debug|Any CPU
459 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|x86.ActiveCfg = Debug|Any CPU
460 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Debug|x86.Build.0 = Debug|Any CPU
461 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
462 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|Any CPU.Build.0 = Release|Any CPU
463 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|ARM64.ActiveCfg = Release|Any CPU
464 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|ARM64.Build.0 = Release|Any CPU
465 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|x64.ActiveCfg = Release|Any CPU
466 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|x64.Build.0 = Release|Any CPU
467 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|x86.ActiveCfg = Release|Any CPU
468 {392817AE-4493-4BED-A7FD-2399379E1B1C}.Release|x86.Build.0 = Release|Any CPU
451 EndGlobalSection 469 EndGlobalSection
452 GlobalSection(SolutionProperties) = preSolution 470 GlobalSection(SolutionProperties) = preSolution
453 HideSolutionNode = FALSE 471 HideSolutionNode = FALSE
@@ -463,6 +481,7 @@ Global
463 {9D788104-2636-4E4C-891C-08FF05FEC31E} = {1284331E-BC6C-426D-AAAF-140C0174F875} 481 {9D788104-2636-4E4C-891C-08FF05FEC31E} = {1284331E-BC6C-426D-AAAF-140C0174F875}
464 {93645356-5D5F-45DE-AC7F-252D35E1ACE5} = {1284331E-BC6C-426D-AAAF-140C0174F875} 482 {93645356-5D5F-45DE-AC7F-252D35E1ACE5} = {1284331E-BC6C-426D-AAAF-140C0174F875}
465 {A05698E0-30D9-4B36-8F3B-585A99D67118} = {1284331E-BC6C-426D-AAAF-140C0174F875} 483 {A05698E0-30D9-4B36-8F3B-585A99D67118} = {1284331E-BC6C-426D-AAAF-140C0174F875}
484 {392817AE-4493-4BED-A7FD-2399379E1B1C} = {1284331E-BC6C-426D-AAAF-140C0174F875}
466 EndGlobalSection 485 EndGlobalSection
467 GlobalSection(ExtensibilityGlobals) = postSolution 486 GlobalSection(ExtensibilityGlobals) = postSolution
468 SolutionGuid = {BB8820D5-723D-426D-B4A0-4D221603C5FA} 487 SolutionGuid = {BB8820D5-723D-426D-B4A0-4D221603C5FA}