diff --git a/pkg/dependency/parser/golang/binary/parse.go b/pkg/dependency/parser/golang/binary/parse.go index 171d3574800e..9ca6e71378f5 100644 --- a/pkg/dependency/parser/golang/binary/parse.go +++ b/pkg/dependency/parser/golang/binary/parse.go @@ -159,7 +159,7 @@ func (p *Parser) ParseLDFlags(name string, flags []string) string { func isValidXKey(key string) bool { key = strings.ToLower(key) // The check for a 'ver' prefix enables the parser to pick up Trivy's own version value that's set. - return strings.HasSuffix(key, "version") || strings.HasSuffix(key, "ver") + return strings.HasSuffix(key, ".version") || strings.HasSuffix(key, ".ver") } func isValidSemVer(ver string) bool { diff --git a/pkg/dependency/parser/golang/binary/parse_test.go b/pkg/dependency/parser/golang/binary/parse_test.go index c93d038c6d8b..e5d0d2e3ae6b 100644 --- a/pkg/dependency/parser/golang/binary/parse_test.go +++ b/pkg/dependency/parser/golang/binary/parse_test.go @@ -227,6 +227,18 @@ func TestParser_ParseLDFlags(t *testing.T) { }, want: "0.50.1", }, + { + name: "with version with extra prefix", + args: args{ + name: "github.com/argoproj/argo-cd/v2", + flags: []string{ + "-s", + "-w", + "-X='github.com/argoproj/argo-cd/v2/common.kubectlVersion=v0.26.11'", + }, + }, + want: "", + }, { name: "with no flags", args: args{