Skip to content

Commit 05502e3

Browse files
committed
golang: workaround +incompatible+dirty go1.24 versions
Try to workaround the +incompatible+dirty versions that go1.24 generates. See: - anchore#2482 - golang/go#71969
1 parent 89b6a52 commit 05502e3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

grype/matcher/golang/matcher.go

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/anchore/grype/grype/matcher/internal"
88
"github.com/anchore/grype/grype/pkg"
99
"github.com/anchore/grype/grype/vulnerability"
10+
"github.com/anchore/grype/internal/log"
1011
syftPkg "github.com/anchore/syft/syft/pkg"
1112
)
1213

@@ -60,6 +61,13 @@ func (m *Matcher) Match(store vulnerability.Provider, p pkg.Package) ([]match.Ma
6061
return matches, nil, nil
6162
}
6263

64+
// go1.24 started to generate versions in the form +incompatible+dirty, which
65+
// fail to be matched: https://github.com/anchore/grype/issues/2482.
66+
if p.Name == mainModule && strings.HasSuffix(p.Version, "+incompatible+dirty") {
67+
log.WithFields("package", p.Name, "version", p.Version).Warn("main module has +incompatible+dirty suffix, trimming +dirty")
68+
p.Version = strings.TrimSuffix(p.Version, "+dirty")
69+
}
70+
6371
return internal.MatchPackageByEcosystemAndCPEs(store, p, m.Type(), searchByCPE(p.Name, m.cfg))
6472
}
6573

0 commit comments

Comments
 (0)