mirror of
https://github.com/securego/gosec.git
synced 2025-07-03 00:27:05 +02:00
Allows the exclude-dir option to exclude sub directories
This commit is contained in:
@ -402,7 +402,7 @@ func PackagePaths(root string, excludes []*regexp.Regexp) ([]string, error) {
|
||||
err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
|
||||
if filepath.Ext(path) == ".go" {
|
||||
path = filepath.Dir(path)
|
||||
if isExcluded(path, excludes) {
|
||||
if isExcluded(filepath.ToSlash(path), excludes) {
|
||||
return nil
|
||||
}
|
||||
paths[path] = true
|
||||
@ -437,7 +437,7 @@ func isExcluded(str string, excludes []*regexp.Regexp) bool {
|
||||
func ExcludedDirsRegExp(excludedDirs []string) []*regexp.Regexp {
|
||||
var exps []*regexp.Regexp
|
||||
for _, excludedDir := range excludedDirs {
|
||||
str := fmt.Sprintf(`([\\/])?%s([\\/])?`, excludedDir)
|
||||
str := fmt.Sprintf(`([\\/])?%s([\\/])?`, strings.ReplaceAll(filepath.ToSlash(excludedDir), "/", `\/`))
|
||||
r := regexp.MustCompile(str)
|
||||
exps = append(exps, r)
|
||||
}
|
||||
|
Reference in New Issue
Block a user