Skip to content

Commit afb4f9d

Browse files
authored
fix(go): include only .version|.ver (no prefixes) ldflags for gobinaries (#6705)
1 parent c96f2a5 commit afb4f9d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/dependency/parser/golang/binary/parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (p *Parser) ParseLDFlags(name string, flags []string) string {
166166
func isValidXKey(key string) bool {
167167
key = strings.ToLower(key)
168168
// The check for a 'ver' prefix enables the parser to pick up Trivy's own version value that's set.
169-
return strings.HasSuffix(key, "version") || strings.HasSuffix(key, "ver")
169+
return strings.HasSuffix(key, ".version") || strings.HasSuffix(key, ".ver")
170170
}
171171

172172
func isValidSemVer(ver string) bool {

pkg/dependency/parser/golang/binary/parse_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ func TestParser_ParseLDFlags(t *testing.T) {
238238
},
239239
want: "0.50.1",
240240
},
241+
{
242+
name: "with version with extra prefix",
243+
args: args{
244+
name: "github.com/argoproj/argo-cd/v2",
245+
flags: []string{
246+
"-s",
247+
"-w",
248+
"-X='github.com/argoproj/argo-cd/v2/common.kubectlVersion=v0.26.11'",
249+
},
250+
},
251+
want: "",
252+
},
241253
{
242254
name: "with no flags",
243255
args: args{

0 commit comments

Comments
 (0)