Skip to content

Commit c94392d

Browse files
committed
fix broken test
1 parent 6164412 commit c94392d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

utils/formats/cdxutils/cyclonedxutils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ func Exclude(bom cyclonedx.BOM, componentsToExclude ...cyclonedx.Component) (fil
282282
return &bom
283283
}
284284
filteredSbom = &bom
285+
rootsCount := len(GetRootDependenciesEntries(&bom, true))
285286
for _, compToExclude := range componentsToExclude {
286-
if matchedBomComp := SearchComponentByRef(bom.Components, compToExclude.BOMRef); matchedBomComp == nil || GetComponentRelation(&bom, matchedBomComp.BOMRef) == RootRelation {
287+
// We ensure we don't trim the entire tree, therefore - we check that the specific component is not the only root in the tree
288+
if matchedBomComp := SearchComponentByRef(bom.Components, compToExclude.BOMRef); matchedBomComp == nil || (rootsCount == 1 && GetComponentRelation(&bom, matchedBomComp.BOMRef) == RootRelation) || strings.Contains(compToExclude.BOMRef, "generic:root") {
287289
// If not a match or Root component, skip it
288290
continue
289291
}

0 commit comments

Comments
 (0)