Skip to content

Commit

Permalink
Do not crash on Subdirectory when missing Component Directory attribute
Browse files Browse the repository at this point in the history
Fixes 7407
  • Loading branch information
robmen committed Jun 3, 2023
1 parent 2fa6703 commit b4fe940
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/wix/WixToolset.Core/Compiler.cs
Expand Up @@ -2254,8 +2254,7 @@ private void ParseComponentElement(XElement node, ComplexReferenceParentType par
{
this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Directory"));
}

if (!String.IsNullOrEmpty(subdirectory))
else if (!String.IsNullOrEmpty(subdirectory))
{
directoryId = this.Core.CreateDirectoryReferenceFromInlineSyntax(sourceLineNumbers, directoryId, subdirectory);
}
Expand Down
31 changes: 30 additions & 1 deletion src/wix/test/WixToolsetTest.CoreIntegration/ComponentFixture.cs
Expand Up @@ -34,12 +34,41 @@ public void CanDetectDuplicateComponentGuids()
});

var errors = result.Messages.Where(m => m.Level == MessageLevel.Error);
Array.Equals(new[]
Assert.Equal(new[]
{
369,
369
}, errors.Select(e => e.Id).ToArray());
}
}

[Fact]
public void CannotBuildMissingDirectoryAttributeWithSubdirectory()
{
var folder = TestData.Get(@"TestData");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, "bin", "test.msi");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, "Component", "MissingDirectoryWithSubdirectory.wxs"),
Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"),
"-bindpath", Path.Combine(folder, "SingleFile", "data"),
"-intermediateFolder", intermediateFolder,
"-o", msiPath
});

var errors = result.Messages.Select(m => m.ToString()).ToArray();
WixAssert.CompareLineByLine(new[]
{
"The Component/@Directory attribute was not found; it is required."
}, errors);
}
}
}
}
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<ComponentGroup Id="ProductComponents">
<Component Subdirectory="fails\without\Directory\attribute">
<File Source="test.txt" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>

0 comments on commit b4fe940

Please sign in to comment.