Skip to content

Commit bdf6013

Browse files
committed
MergeCommand.cs: use new cyclonedx-dotnet-library features to CleanupMetadataComponent() and CleanupEmptyLists() as a finishing touch, to avoid inducing a spec violation with a duplicate bom-ref
1 parent 5de8d19 commit bdf6013

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/cyclonedx/Commands/MergeCommand.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public static async Task<int> Merge(MergeCommandOptions options)
8989
}
9090
else
9191
{
92-
// otherwise use the first non-null component from the input BOMs as the default
92+
// otherwise use the first non-null component from the input
93+
// BOMs as the default; note CleanupMetadataComponent() below
94+
// to ensure that such bom-ref exists in the document only once.
9395
foreach (var bom in inputBoms)
9496
{
9597
if(bom.Metadata != null && bom.Metadata.Component != null)
@@ -101,8 +103,19 @@ public static async Task<int> Merge(MergeCommandOptions options)
101103
}
102104
}
103105

106+
outputBom = CycloneDXUtils.CleanupMetadataComponent(outputBom);
107+
outputBom = CycloneDXUtils.CleanupEmptyLists(outputBom);
108+
104109
outputBom.Version = 1;
105110
outputBom.SerialNumber = "urn:uuid:" + System.Guid.NewGuid().ToString();
111+
if (outputBom.Metadata is null)
112+
{
113+
outputBom.Metadata = new Metadata();
114+
}
115+
if (outputBom.Metadata.Timestamp is null)
116+
{
117+
outputBom.Metadata.Timestamp = DateTime.Now;
118+
}
106119

107120
if (!outputToConsole)
108121
{

0 commit comments

Comments
 (0)