From a896fec453056aa5e1ad803b04a672d2dceda981 Mon Sep 17 00:00:00 2001
From: Sean Hall <r.sean.hall@gmail.com>
Date: Wed, 3 Aug 2022 13:56:54 -0500
Subject: Fix converting empty inner text.

Add failing test for commented inner text.
---
 src/wix/WixToolset.Converters/WixConverter.cs      |   8 +-
 .../WixToolsetTest.Converters/ConditionFixture.cs  | 109 +++++++++++++++++++++
 .../BundleFixture.cs                               |  37 +++++++
 .../WixToolsetTest.CoreIntegration/MsiFixture.cs   |   3 +
 .../TestData/IncludePath/Bundle.en-us.wxl          |   6 ++
 .../TestData/IncludePath/Bundle.wxs                |  13 +++
 .../TestData/IncludePath/Package.wxs               |   2 +-
 .../TestData/IncludePath/data/Bundle.wxi           |   3 +
 .../TestData/IncludePath/data/Package.wxi          |   1 +
 9 files changed, 178 insertions(+), 4 deletions(-)
 create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl
 create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs
 create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi

(limited to 'src')

diff --git a/src/wix/WixToolset.Converters/WixConverter.cs b/src/wix/WixToolset.Converters/WixConverter.cs
index 57069902..9b0bebc1 100644
--- a/src/wix/WixToolset.Converters/WixConverter.cs
+++ b/src/wix/WixToolset.Converters/WixConverter.cs
@@ -2274,15 +2274,17 @@ namespace WixToolset.Converters
         private static bool TryGetInnerText(XElement element, out string value)
         {
             value = null;
+            var found = false;
 
-            var nodes = element.Nodes();
+            var nodes = element.Nodes().ToList();
 
-            if (nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA))
+            if (nodes.Any() && nodes.All(e => e.NodeType == XmlNodeType.Text || e.NodeType == XmlNodeType.CDATA))
             {
                 value = String.Join(String.Empty, nodes.Cast<XText>().Select(TrimTextValue));
+                found = true;
             }
 
-            return !String.IsNullOrEmpty(value);
+            return found;
         }
 
         private static bool IsTextNode(XNode node, out XText text)
diff --git a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs
index d3f65aeb..daf66a8b 100644
--- a/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs
+++ b/src/wix/test/WixToolsetTest.Converters/ConditionFixture.cs
@@ -139,6 +139,115 @@ namespace WixToolsetTest.Converters
             WixAssert.CompareLineByLine(expected, actualLines);
         }
 
+        [Fact]
+        public void FixEmptyCondition()
+        {
+            var parse = String.Join(Environment.NewLine,
+                "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
+                "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
+                "  <Fragment>",
+                "    <Condition Message='Empty new line'>",
+                "    </Condition>",
+                "    <Condition Message='Empty cdata'><![CDATA[]]></Condition>",
+                "  </Fragment>",
+                "</Wix>");
+
+            var expected = new[]
+            {
+                "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
+                "  <Fragment>",
+                "    <Launch Condition=\"\" Message=\"Empty new line\" />",
+                "    <Launch Condition=\"\" Message=\"Empty cdata\" />",
+                "  </Fragment>",
+                "</Wix>"
+            };
+
+            var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
+
+            var messaging = new MockMessaging();
+            var converter = new WixConverter(messaging, 2, null, null);
+
+            var errors = converter.ConvertDocument(document);
+
+            var actualLines = UnformattedDocumentLines(document);
+            WixAssert.CompareLineByLine(expected, actualLines);
+
+            Assert.Equal(4, errors);
+        }
+
+        [Fact(Skip = "Test demonstrates failure")]
+        public void FixConditionWithComment()
+        {
+            var parse = String.Join(Environment.NewLine,
+                "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
+                "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
+                "  <Fragment>",
+                "    <Condition Message='commented cdata'>",
+                "        <!-- commented condition -->",
+                "        <![CDATA[cdatacontent]]>",
+                "    </Condition>",
+                "  </Fragment>",
+                "</Wix>");
+
+            //TODO: expected value is not set in stone but must have replaced Condition element with Launch and should have kept the comment.
+            var expected = new[]
+            {
+                "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
+                "  <Fragment>",
+                "    <Launch Condition=\"cdatacontent\" Message=\"commented cdata\" />",
+                "        <!-- commented condition -->",
+                "  </Fragment>",
+                "</Wix>"
+            };
+
+            var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
+
+            var messaging = new MockMessaging();
+            var converter = new WixConverter(messaging, 2, null, null);
+
+            var errors = converter.ConvertDocument(document);
+
+            var actualLines = UnformattedDocumentLines(document);
+            WixAssert.CompareLineByLine(expected, actualLines);
+
+            Assert.Equal(2, errors);
+        }
+
+        [Fact]
+        public void FixConditionFromWxi()
+        {
+            var parse = String.Join(Environment.NewLine,
+                "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
+                "<Include xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
+                "  <Fragment>",
+                "    <Condition Message='from wxi'>",
+                "        wxicondition",
+                "    </Condition>",
+                "  </Fragment>",
+                "</Include>");
+
+            var expected = new[]
+            {
+                "<Include xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
+                "  <Fragment>",
+                "    <Launch Condition=\"wxicondition\" Message=\"from wxi\" />",
+                "  </Fragment>",
+                "</Include>"
+            };
+
+            var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
+
+            var messaging = new MockMessaging();
+            var converter = new WixConverter(messaging, 2, null, null);
+
+            var errors = converter.ConvertDocument(document);
+
+            var actualLines = UnformattedDocumentLines(document);
+            WixAssert.CompareLineByLine(expected, actualLines);
+
+            Assert.Equal(3, errors);
+        }
+
         [Fact]
         public void FixFeatureCondition()
         {
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
index 132e93e6..c7dd4cfa 100644
--- a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
@@ -306,6 +306,43 @@ namespace WixToolsetTest.CoreIntegration
             }
         }
 
+        [Fact]
+        public void CanBuildSimpleBundleUsingInclude()
+        {
+            var folder = TestData.Get(@"TestData", "IncludePath");
+            var dataFolder = TestData.Get(@"TestData", "SimpleBundle", "data");
+
+            using (var fs = new DisposableFileSystem())
+            {
+                var baseFolder = fs.GetFolder();
+                var intermediateFolder = Path.Combine(baseFolder, "obj");
+                var exePath = Path.Combine(baseFolder, @"bin\test.exe");
+                var pdbPath = Path.Combine(baseFolder, @"bin\test.wixpdb");
+
+                var result = WixRunner.Execute(new[]
+                {
+                    "build",
+                    Path.Combine(folder, "Bundle.wxs"),
+                    "-loc", Path.Combine(folder, "Bundle.en-us.wxl"),
+                    "-bindpath", dataFolder,
+                    "-intermediateFolder", intermediateFolder,
+                    "-o", exePath,
+                });
+
+                result.AssertSuccess();
+
+                using (var wixOutput = WixOutput.Read(pdbPath))
+                {
+
+                    var intermediate = Intermediate.Load(wixOutput);
+                    var section = intermediate.Sections.Single();
+
+                    var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single();
+                    WixAssert.StringEqual("~IncludeTestBundle", bundleSymbol.Name);
+                }
+            }
+        }
+
         [Fact]
         public void CanBuildSingleExeBundle()
         {
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
index c1c07952..0c01fa5e 100644
--- a/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
@@ -535,6 +535,9 @@ namespace WixToolsetTest.CoreIntegration
                 var fileSymbol = section.Symbols.OfType<FileSymbol>().Single();
                 WixAssert.StringEqual(Path.Combine(folder, @"data\test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path);
                 WixAssert.StringEqual(@"test.txt", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath().Path);
+
+                var featureSymbol = Assert.Single(section.Symbols.OfType<FeatureSymbol>());
+                WixAssert.StringEqual("MsiPackage", featureSymbol.Title);
             }
         }
 
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl
new file mode 100644
index 00000000..fb2131ce
--- /dev/null
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.en-us.wxl
@@ -0,0 +1,6 @@
+<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">
+
+  <String Id="BundleName">~IncludeTestBundle</String>
+  <String Id="BundleInProgressName">~InProgressTestBundle</String>
+
+</WixLocalization>
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs
new file mode 100644
index 00000000..5e001c9a
--- /dev/null
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Bundle.wxs
@@ -0,0 +1,13 @@
+<?include data\Bundle.wxi ?>
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
+  <Bundle Name="$(var.BundleLocName)" InProgressName="!(loc.BundleInProgressName)" Version="!(bind.packageVersion.test.msi)" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
+    <BootstrapperApplication>
+      <BootstrapperApplicationDll SourceFile="fakeba.dll" />
+    </BootstrapperApplication>
+    <Chain>
+      <MsiPackage SourceFile="test.msi">
+        <MsiProperty Name="TEST" Value="1" />
+      </MsiPackage>
+    </Chain>
+  </Bundle>
+</Wix>
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs
index 0bd80c50..2f789908 100644
--- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/Package.wxs
@@ -5,7 +5,7 @@
 
     <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
 
-    <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
+    <Feature Id="ProductFeature" Title="$(var.FeatureTitleName)">
       <ComponentGroupRef Id="ProductComponents" />
     </Feature>
   </Package>
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi
new file mode 100644
index 00000000..0ad96e6c
--- /dev/null
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Bundle.wxi
@@ -0,0 +1,3 @@
+<Include xmlns="http://wixtoolset.org/schemas/v4/wxs">
+  <?define BundleLocName = "!(loc.BundleName)" ?>
+</Include>
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi
index f2df3b86..76ebfad6 100644
--- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/IncludePath/data/Package.wxi
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Include xmlns="http://wixtoolset.org/schemas/v4/wxs">
   <?define ProductVersion = "1.2.3" ?>
+  <?define FeatureTitleName = "!(loc.FeatureTitle)" ?>
 </Include>
-- 
cgit v1.2.3-55-g6feb