@joebigelow / wix-1 / commits / 3b617d74

Do not crash on Subdirectory when missing Component Directory attribute

Fixes 7407

Rob Mensching committed Apr 18, 2023 at 09:02 UTC 3b617d74241cb54fcbb85989538a681f7134349b
3 files changed +41 -3
src/wix/WixToolset.Core/Compiler.cs
+1 -2
@@ -2254,8 +2254,7 @@ namespace WixToolset.Core
2254 {
2255 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Directory"));
2256 }
2257 -
2258 - if (!String.IsNullOrEmpty(subdirectory))
2257 + else if (!String.IsNullOrEmpty(subdirectory))
2258 {
2259 directoryId = this.Core.CreateDirectoryReferenceFromInlineSyntax(sourceLineNumbers, directoryId, subdirectory);
2260 }
src/wix/test/WixToolsetTest.CoreIntegration/ComponentFixture.cs
+30 -1
@@ -34,12 +34,41 @@ namespace WixToolsetTest.CoreIntegration
34 });
35
36 var errors = result.Messages.Where(m => m.Level == MessageLevel.Error);
37 - Array.Equals(new[]
37 + Assert.Equal(new[]
38 {
39 369,
40 369
41 }, errors.Select(e => e.Id).ToArray());
42 }
43 }
44 +
45 + [Fact]
46 + public void CannotBuildMissingDirectoryAttributeWithSubdirectory()
47 + {
48 + var folder = TestData.Get(@"TestData");
49 +
50 + using (var fs = new DisposableFileSystem())
51 + {
52 + var baseFolder = fs.GetFolder();
53 + var intermediateFolder = Path.Combine(baseFolder, "obj");
54 + var msiPath = Path.Combine(baseFolder, "bin", "test.msi");
55 +
56 + var result = WixRunner.Execute(new[]
57 + {
58 + "build",
59 + Path.Combine(folder, "Component", "MissingDirectoryWithSubdirectory.wxs"),
60 + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"),
61 + "-bindpath", Path.Combine(folder, "SingleFile", "data"),
62 + "-intermediateFolder", intermediateFolder,
63 + "-o", msiPath
64 + });
65 +
66 + var errors = result.Messages.Select(m => m.ToString()).ToArray();
67 + WixAssert.CompareLineByLine(new[]
68 + {
69 + "The Component/@Directory attribute was not found; it is required."
70 + }, errors);
71 + }
72 + }
73 }
74 }
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Component/MissingDirectoryWithSubdirectory.wxs new
+10
@@ -0,0 +1,10 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Fragment>
4 + <ComponentGroup Id="ProductComponents">
5 + <Component Subdirectory="fails\without\Directory\attribute">
6 + <File Source="test.txt" />
7 + </Component>
8 + </ComponentGroup>
9 + </Fragment>
10 +</Wix>