@@ -10,6 +10,7 @@ import (
1010 "runtime"
1111 "strings"
1212 "time"
13+ "unicode"
1314
1415 "github.com/golangci/golangci-lint/pkg/logutils"
1516)
@@ -84,9 +85,9 @@ func (b Builder) Build(ctx context.Context) error {
8485}
8586
8687func (b Builder ) clone (ctx context.Context ) error {
87- //nolint:gosec
88+ //nolint:gosec // the variable is sanitized.
8889 cmd := exec .CommandContext (ctx ,
89- "git" , "clone" , "--branch" , b .cfg .Version ,
90+ "git" , "clone" , "--branch" , sanitizeVersion ( b .cfg .Version ) ,
9091 "--single-branch" , "--depth" , "1" , "-c advice.detachedHead=false" , "-q" ,
9192 "https://github.com/golangci/golangci-lint.git" ,
9293 )
@@ -141,12 +142,12 @@ func (b Builder) goModTidy(ctx context.Context) error {
141142}
142143
143144func (b Builder ) goBuild (ctx context.Context , binaryName string ) error {
144- //nolint:gosec
145+ //nolint:gosec // the variable is sanitized.
145146 cmd := exec .CommandContext (ctx , "go" , "build" ,
146147 "-ldflags" ,
147148 fmt .Sprintf (
148149 "-s -w -X 'main.version=%s-mygcl' -X 'main.date=%s'" ,
149- b .cfg .Version , time .Now ().UTC ().String (),
150+ sanitizeVersion ( b .cfg .Version ) , time .Now ().UTC ().String (),
150151 ),
151152 "-o" , binaryName ,
152153 "./cmd/golangci-lint" ,
@@ -208,3 +209,11 @@ func (b Builder) getBinaryName() string {
208209
209210 return name
210211}
212+
213+ func sanitizeVersion (v string ) string {
214+ fn := func (c rune ) bool {
215+ return ! (unicode .IsLetter (c ) || unicode .IsNumber (c ) || c == '.' || c == '/' )
216+ }
217+
218+ return strings .Join (strings .FieldsFunc (v , fn ), "" )
219+ }
0 commit comments