@joebigelow / wix / commits / 02b8f1a1

Always try to normalize the Bundle UpgradeCode in the backend

Fixes 6008

Rob Mensching committed Mar 11, 2022 at 17:16 UTC 02b8f1a145724d889f95761390dc6223289764ac
4 files changed +59
src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
+16
@@ -102,6 +102,8 @@ namespace WixToolset.Core.Burn
102
103 bundleSymbol.ProviderKey = bundleSymbol.BundleId = Guid.NewGuid().ToString("B").ToUpperInvariant();
104
105 + bundleSymbol.UpgradeCode = this.NormalizeBundleUpgradeCode(bundleSymbol.SourceLineNumbers, bundleSymbol.UpgradeCode);
106 +
107 bundleSymbol.Attributes |= WixBundleAttributes.PerMachine; // default to per-machine but the first-per user package wil flip the bundle per-user.
108
109 // Ensure there is one and only one WixBootstrapperApplicationDllSymbol.
@@ -494,6 +496,20 @@ namespace WixToolset.Core.Burn
496 this.Wixout = this.CreateWixout(trackedFiles, this.Output, manifestPath, baManifestPath, bextManifestPath);
497 }
498
499 + private string NormalizeBundleUpgradeCode(SourceLineNumber sourceLineNumber, string upgradeCode)
500 + {
501 + if (Guid.TryParse(upgradeCode, out var guid))
502 + {
503 + return guid.ToString("B").ToUpperInvariant();
504 + }
505 + else
506 + {
507 + this.Messaging.Write(ErrorMessages.IllegalGuidValue(sourceLineNumber, "Bundle", "UpgradeCode", upgradeCode));
508 + }
509 +
510 + return upgradeCode;
511 + }
512 +
513 private WixOutput CreateWixout(List<ITrackedFile> trackedFiles, Intermediate intermediate, string manifestPath, string baDataPath, string bextDataPath)
514 {
515 WixOutput wixout;
src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs
+29
@@ -319,6 +319,35 @@ namespace WixToolsetTest.CoreIntegration
319 }
320 }
321
322 + [Fact]
323 + public void CannotBuildBundleWithInvalidUpgradeCode()
324 + {
325 + var folder = TestData.Get(@"TestData");
326 +
327 + using (var fs = new DisposableFileSystem())
328 + {
329 + var baseFolder = fs.GetFolder();
330 + var intermediateFolder = Path.Combine(baseFolder, "obj");
331 +
332 + var result = WixRunner.Execute(new[]
333 + {
334 + "build",
335 + Path.Combine(folder, "BundleWithInvalid", "BundleWithInvalidUpgradeCode.wxs"),
336 + "-loc", Path.Combine(folder, "BundleWithInvalid", "BundleWithInvalidUpgradeCode.wxl"),
337 + "-bindpath", Path.Combine(folder, ".Data"),
338 + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"),
339 + "-intermediateFolder", intermediateFolder,
340 + "-o", Path.Combine(baseFolder, @"bin\test.exe")
341 + });
342 +
343 + var message = result.Messages.Where(m => m.Level == MessageLevel.Error).Select(m => m.ToString().Replace(folder, "<testdata>")).ToArray();
344 + WixAssert.CompareLineByLine(new[]
345 + {
346 + "The Bundle/@UpgradeCode attribute's value, 'NOT-A-GUID', is not a legal guid value."
347 + }, message);
348 + }
349 + }
350 +
351 [Fact]
352 public void CanBuildUncompressedBundle()
353 {
src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxl new
+3
@@ -0,0 +1,3 @@
1 +<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">
2 + <String Id="InvalidUpgradeCode">NOT-A-GUID</String>
3 +</WixLocalization>
src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithInvalidUpgradeCode.wxs new
+11
@@ -0,0 +1,11 @@
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2 + <Bundle Name="BundleWithInvalidUpgradeCode"
3 + Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="!(loc.InvalidUpgradeCode)">
4 + <BootstrapperApplication>
5 + <BootstrapperApplicationDll SourceFile="fakeba.dll" />
6 + </BootstrapperApplication>
7 + <Chain>
8 + <ExePackage DetectCondition="DetectedSomething" UninstallArguments="-uninstall" SourceFile="burn.exe" />
9 + </Chain>
10 + </Bundle>
11 +</Wix>