diff options
author | Rob Mensching <rob@firegiant.com> | 2023-01-06 12:40:07 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2023-01-11 22:05:39 -0800 |
commit | f9804feb02c893bd54986f046ff5246082eaff22 (patch) | |
tree | fddf1754c068bd45d97bcab82436fb2c445ed68b | |
parent | 10794363b90e49885ace5729bb45af4da5d0f220 (diff) | |
download | wix-f9804feb02c893bd54986f046ff5246082eaff22.tar.gz wix-f9804feb02c893bd54986f046ff5246082eaff22.tar.bz2 wix-f9804feb02c893bd54986f046ff5246082eaff22.zip |
Correctly convert Controls with multiple Conditions with same action
Fixes 7142
-rw-r--r-- | src/wix/WixToolset.Converters/WixConverter.cs | 12 | ||||
-rw-r--r-- | src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs | 43 |
2 files changed, 54 insertions, 1 deletions
diff --git a/src/wix/WixToolset.Converters/WixConverter.cs b/src/wix/WixToolset.Converters/WixConverter.cs index 3d844b44..f962dc9c 100644 --- a/src/wix/WixToolset.Converters/WixConverter.cs +++ b/src/wix/WixToolset.Converters/WixConverter.cs | |||
@@ -1013,6 +1013,7 @@ namespace WixToolset.Converters | |||
1013 | { | 1013 | { |
1014 | var xConditions = element.Elements(ConditionElementName).ToList(); | 1014 | var xConditions = element.Elements(ConditionElementName).ToList(); |
1015 | var comments = new List<XNode>(); | 1015 | var comments = new List<XNode>(); |
1016 | var conditions = new List<KeyValuePair<string, string>>(); | ||
1016 | 1017 | ||
1017 | foreach (var xCondition in xConditions) | 1018 | foreach (var xCondition in xConditions) |
1018 | { | 1019 | { |
@@ -1021,10 +1022,19 @@ namespace WixToolset.Converters | |||
1021 | TryGetInnerText(xCondition, out var text, out comments, comments) && | 1022 | TryGetInnerText(xCondition, out var text, out comments, comments) && |
1022 | this.OnInformation(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action)) | 1023 | this.OnInformation(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action)) |
1023 | { | 1024 | { |
1024 | element.Add(new XAttribute(action + "Condition", text)); | 1025 | conditions.Add(new KeyValuePair<string, string>(action, text)); |
1025 | } | 1026 | } |
1026 | } | 1027 | } |
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 | |||
1028 | foreach (var xCondition in xConditions) | 1038 | foreach (var xCondition in xConditions) |
1029 | { | 1039 | { |
1030 | xCondition.Remove(); | 1040 | xCondition.Remove(); |
diff --git a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs index d8a55402..24dee1c6 100644 --- a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs +++ b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs | |||
@@ -55,6 +55,49 @@ namespace WixToolsetTest.Converters | |||
55 | } | 55 | } |
56 | 56 | ||
57 | [Fact] | 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] | ||
58 | public void FixControlConditionWithComment() | 101 | public void FixControlConditionWithComment() |
59 | { | 102 | { |
60 | var parse = String.Join(Environment.NewLine, | 103 | var parse = String.Join(Environment.NewLine, |