@@ -382,23 +382,21 @@ func excludeFromDependencies(dependencies *[]cyclonedx.Dependency, components *[
382382 if dependencies == nil || len (* dependencies ) == 0 || len (excludeComponents ) == 0 {
383383 return dependencies
384384 }
385- excludeRefs := datastructures .MakeSet [string ]()
386385 excludePurls := datastructures .MakeSet [string ]()
387386 for _ , component := range excludeComponents {
388- excludeRefs .Add (component .BOMRef )
389387 excludePurls .Add (techutils .PurlToXrayComponentId (component .PackageURL ))
390388 }
391389 filteredDependencies := []cyclonedx.Dependency {}
392390 for _ , dep := range * dependencies {
393- if excludeRefs .Exists (techutils . PurlToXrayComponentId (dep .Ref )) {
391+ if excludePurls .Exists (GetTrimmedPurl (dep .Ref , components )) {
394392 // This dependency is excluded, skip it
395393 continue
396394 }
397395 filteredDep := cyclonedx.Dependency {Ref : dep .Ref }
398396 if dep .Dependencies != nil {
399397 // Also filter the components from the dependencies of this dependency
400398 for _ , depRef := range * dep .Dependencies {
401- if ! excludeRefs .Exists (depRef ) {
399+ if ! excludePurls .Exists (GetTrimmedPurl ( depRef , components ) ) {
402400 if filteredDep .Dependencies == nil {
403401 filteredDep .Dependencies = & []string {}
404402 }
@@ -413,6 +411,15 @@ func excludeFromDependencies(dependencies *[]cyclonedx.Dependency, components *[
413411 return & filteredDependencies
414412}
415413
414+ func GetTrimmedPurl (dep string , components * []cyclonedx.Component ) string {
415+ component := SearchComponentByRef (components , dep )
416+ if component == nil {
417+ // couldn't find component - skipping
418+ return ""
419+ }
420+ return techutils .PurlToXrayComponentId (component .PackageURL )
421+ }
422+
416423func AttachLicenseToComponent (component * cyclonedx.Component , license cyclonedx.LicenseChoice ) {
417424 if component .Licenses == nil {
418425 component .Licenses = & cyclonedx.Licenses {}
0 commit comments