Skip to content
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
19 changes: 13 additions & 6 deletions syft/pkg/cataloger/golang/parse_go_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,25 @@ func (c *goModCataloger) parseGoModFile(ctx context.Context, resolver file.Resol

// the old path and new path may be the same, in which case this is a noop,
// but if they're different we need to remove the old package.
delete(packages, m.Old.Path)

packages[m.New.Path] = pkg.Package{
Name: m.New.Path,
// note that we may change the path but we should always reference the new version (since the old version
// cannot be trusted as a correct value).
var finalPath string
if !strings.HasPrefix(m.New.Path, ".") && !strings.HasPrefix(m.New.Path, "/") {
finalPath = m.New.Path
delete(packages, m.Old.Path)
} else {
finalPath = m.Old.Path
}
packages[finalPath] = pkg.Package{
Name: finalPath,
Version: m.New.Version,
Licenses: pkg.NewLicenseSet(lics...),
Locations: file.NewLocationSet(reader.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation)),
PURL: packageURL(m.New.Path, m.New.Version),
PURL: packageURL(finalPath, m.New.Version),
Language: pkg.Go,
Type: pkg.GoModulePkg,
Metadata: pkg.GolangModuleEntry{
H1Digest: digests[fmt.Sprintf("%s %s", m.New.Path, m.New.Version)],
H1Digest: digests[fmt.Sprintf("%s %s", finalPath, m.New.Version)],
},
}
}
Expand Down
14 changes: 14 additions & 0 deletions syft/pkg/cataloger/golang/parse_go_mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ func TestParseGoMod(t *testing.T) {
},
},
},
{
fixture: "test-fixtures/relative-replace",
expected: []pkg.Package{
{
Name: "github.com/aws/aws-sdk-go-v2",
Version: "",
PURL: "pkg:golang/github.com/aws/aws-sdk-go-v2",
Locations: file.NewLocationSet(file.NewLocation("test-fixtures/relative-replace")),
Language: pkg.Go,
Type: pkg.GoModulePkg,
Metadata: pkg.GolangModuleEntry{},
},
},
},
{

fixture: "test-fixtures/many-packages",
Expand Down
7 changes: 7 additions & 0 deletions syft/pkg/cataloger/golang/test-fixtures/relative-replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/aws/aws-sdk-go-v2/feature/ec2/imds

go 1.22

require github.com/aws/aws-sdk-go-v2 v1.36.3

replace github.com/aws/aws-sdk-go-v2 => ../../../
Loading