Correctly convert Controls with multiple Conditions with same action
Fixes 7142
Rob Mensching committed
Jan 6, 2023 at 12:40 UTC
f9804feb02c893bd54986f046ff5246082eaff22
2 files changed
+54
-1
src/wix/WixToolset.Converters/WixConverter.cs
+11
-1
@@ -1013,6 +1013,7 @@ namespace WixToolset.Converters
1013
{
1014
var xConditions = element.Elements(ConditionElementName).ToList();
1015
var comments = new List<XNode>();
1016
+ var conditions = new List<KeyValuePair<string, string>>();
1017
1018
foreach (var xCondition in xConditions)
1019
{
@@ -1021,10 +1022,19 @@ namespace WixToolset.Converters
1022
TryGetInnerText(xCondition, out var text, out comments, comments) &&
1023
this.OnInformation(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action))
1024
{
1024
- element.Add(new XAttribute(action + "Condition", text));
1025
+ conditions.Add(new KeyValuePair<string, string>(action, text));
1026
}
1027
}
1028
1029
+ foreach (var actionCondition in conditions.GroupBy(c => c.Key))
1030
+ {
1031
+ var conditionValues = actionCondition.Select(c => c.Value).ToList();
1032
+
1033
+ var finalCondition = (conditionValues.Count == 1) ? conditionValues.Single() : String.Join(" OR ", conditionValues.Select(c => $"({c})"));
1034
+
1035
+ element.Add(new XAttribute(actionCondition.Key + "Condition", finalCondition));
1036
+ }
1037
+
1038
foreach (var xCondition in xConditions)
1039
{
1040
xCondition.Remove();
src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs
+43
@@ -54,6 +54,49 @@ namespace WixToolsetTest.Converters
54
WixAssert.CompareLineByLine(expected, actualLines);
55
}
56
57
+ [Fact]
58
+ public void FixDoubleControlCondition()
59
+ {
60
+ var parse = String.Join(Environment.NewLine,
61
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
62
+ "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
63
+ " <Fragment>",
64
+ " <UI>",
65
+ " <Dialog Id='Dlg1'>",
66
+ " <Control Id='Control1'>",
67
+ " <Condition Action='hide'>x=y</Condition>",
68
+ " <Condition Action='hide'>a<>b</Condition>",
69
+ " </Control>",
70
+ " </Dialog>",
71
+ " </UI>",
72
+ " </Fragment>",
73
+ "</Wix>");
74
+
75
+ var expected = new[]
76
+ {
77
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
78
+ " <Fragment>",
79
+ " <UI>",
80
+ " <Dialog Id=\"Dlg1\">",
81
+ " <Control Id=\"Control1\" HideCondition=\"(x=y) OR (a<>b)\" />",
82
+ " </Dialog>",
83
+ " </UI>",
84
+ " </Fragment>",
85
+ "</Wix>"
86
+ };
87
+
88
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
89
+
90
+ var messaging = new MockMessaging();
91
+ var converter = new WixConverter(messaging, 2, null, null);
92
+
93
+ var errors = converter.ConvertDocument(document);
94
+ Assert.Equal(4, errors);
95
+
96
+ var actualLines = UnformattedDocumentLines(document);
97
+ WixAssert.CompareLineByLine(expected, actualLines);
98
+ }
99
+
100
[Fact]
101
public void FixControlConditionWithComment()
102
{