Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix to check for name without ID #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/licenses/license_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ func getIndividualLicenses(lic string) []string {
sort.Strings(lics)
return lics
}

func LicenseObjectByName(name string) License {
return meta{
name: name,
}
}
15 changes: 11 additions & 4 deletions pkg/search/cdx/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,24 @@ func (doc *cdxDoc) pkgResults(pIndices []int) []results.Package {
for _, val := range pIndices {
comp := doc.allComps[val]

pkgs = append(pkgs, results.Package{
res := results.Package{
Name: comp.Name,
Version: comp.Version,
PURL: comp.PackageURL,
})
}

if doc.opts.DoLicense() {
ls := doc.licenses(comp)
for _, lic := range ls {
pkgs[val].Licenses = append(pkgs[val].Licenses, licenses.LicenseStore{
res.Licenses = append(res.Licenses, licenses.LicenseStore{
Nm: lic.Name(),
Ss: lic.ShortID(),
Ds: lic.Deprecated(),
})
}
}

pkgs = append(pkgs, res)
}

return pkgs
Expand All @@ -87,7 +90,11 @@ func (c *cdxDoc) licenses(comp *cydx.Component) []licenses.License {
if cl.Expression != "" {
addLicense(&lics, licenses.NewLicenseFromID(cl.Expression))
} else if cl.License != nil {
addLicense(&lics, licenses.NewLicenseFromID(cl.License.ID))
if cl.License.ID != "" {
addLicense(&lics, licenses.NewLicenseFromID(cl.License.ID))
} else {
addLicense(&lics, []licenses.License{licenses.LicenseObjectByName(cl.License.Name)})
}
}
}

Expand Down