detect license ID from full text when incidentally provided as a value (#3876)

---------
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Christopher Angelo Phillips
2025-05-13 16:37:18 -04:00
committed by GitHub
co-authored by Alex Goodman
parent b4d717fb30
commit f77d503892
117 changed files with 2082 additions and 1327 deletions
+4 -2
View File
@@ -1,6 +1,8 @@
package ruby
import (
"context"
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg"
@@ -21,12 +23,12 @@ func newGemfileLockPackage(name, version string, locations ...file.Location) pkg
return p
}
func newGemspecPackage(m gemData, gemSpecLocation file.Location) pkg.Package {
func newGemspecPackage(ctx context.Context, m gemData, gemSpecLocation file.Location) pkg.Package {
p := pkg.Package{
Name: m.Name,
Version: m.Version,
Locations: file.NewLocationSet(gemSpecLocation.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation)),
Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromLocation(gemSpecLocation, m.Licenses...)...),
Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromLocationWithContext(ctx, gemSpecLocation, m.Licenses...)...),
PURL: packageURL(m.Name, m.Version),
Language: pkg.Ruby,
Type: pkg.GemPkg,
+2 -1
View File
@@ -66,7 +66,7 @@ func processList(s string) []string {
}
// parseGemSpecEntries parses the gemspec file and returns the packages and relationships found.
func parseGemSpecEntries(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
func parseGemSpecEntries(ctx context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
var pkgs []pkg.Package
var fields = make(map[string]interface{})
scanner := bufio.NewScanner(reader)
@@ -105,6 +105,7 @@ func parseGemSpecEntries(_ context.Context, _ file.Resolver, _ *generic.Environm
pkgs = append(
pkgs,
newGemspecPackage(
ctx,
metadata,
reader.Location,
),
@@ -1,6 +1,7 @@
package ruby
import (
"context"
"testing"
"github.com/anchore/syft/syft/file"
@@ -10,7 +11,7 @@ import (
func TestParseGemspec(t *testing.T) {
fixture := "test-fixtures/bundler.gemspec"
ctx := context.TODO()
locations := file.NewLocationSet(file.NewLocation(fixture))
var expectedPkg = pkg.Package{
@@ -20,7 +21,7 @@ func TestParseGemspec(t *testing.T) {
Locations: locations,
Type: pkg.GemPkg,
Licenses: pkg.NewLicenseSet(
pkg.NewLicenseFromLocations("MIT", file.NewLocation(fixture)),
pkg.NewLicenseFromLocationsWithContext(ctx, "MIT", file.NewLocation(fixture)),
),
Language: pkg.Ruby,
Metadata: pkg.RubyGemspec{