fix: comma in exclude pattern leads to unexpected results (#1917)

This commit is contained in:
Ludovic Fernandez 2021-04-19 15:20:49 +02:00 committed by GitHub
parent 2c008326ba
commit 9cb902cdf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -313,8 +313,15 @@ func fixSlicesFlags(fs *pflag.FlagSet) {
return return
} }
var safe []string
for _, v := range s {
// add quotes to escape comma because spf13/pflag use a CSV parser:
// https://github.com/spf13/pflag/blob/85dd5c8bc61cfa382fecd072378089d4e856579d/string_slice.go#L43
safe = append(safe, `"`+v+`"`)
}
// calling Set sets Changed to true: next Set calls will append, not overwrite // calling Set sets Changed to true: next Set calls will append, not overwrite
_ = f.Value.Set(strings.Join(s, ",")) _ = f.Value.Set(strings.Join(safe, ","))
}) })
} }

View File

@ -7,7 +7,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
homedir "github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/fsutils"

View File

@ -237,9 +237,9 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s
func getExcludeProcessor(cfg *config.Issues) processors.Processor { func getExcludeProcessor(cfg *config.Issues) processors.Processor {
var excludeTotalPattern string var excludeTotalPattern string
excludeGlobalPatterns := cfg.ExcludePatterns
if len(excludeGlobalPatterns) != 0 { if len(cfg.ExcludePatterns) != 0 {
excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludeGlobalPatterns, "|")) excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(cfg.ExcludePatterns, "|"))
} }
var excludeProcessor processors.Processor var excludeProcessor processors.Processor