From afb4f9dc4730671ba004e1734fa66422c4c86dad Mon Sep 17 00:00:00 2001 From: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com> Date: Fri, 17 May 2024 13:55:24 +0600 Subject: [PATCH] fix(go): include only `.version`|`.ver` (no prefixes) ldflags for `gobinaries` (#6705) --- pkg/dependency/parser/golang/binary/parse.go | 2 +- pkg/dependency/parser/golang/binary/parse_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/dependency/parser/golang/binary/parse.go b/pkg/dependency/parser/golang/binary/parse.go index 4c53858c69e9..0354668c33cc 100644 --- a/pkg/dependency/parser/golang/binary/parse.go +++ b/pkg/dependency/parser/golang/binary/parse.go @@ -166,7 +166,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 13cc1e682f9c..95e620d412bd 100644 --- a/pkg/dependency/parser/golang/binary/parse_test.go +++ b/pkg/dependency/parser/golang/binary/parse_test.go @@ -238,6 +238,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{