mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 03:55:54 +00:00
Add support for partial path match in the skip option
This commit is contained in:
parent
05738474a1
commit
3ae2762bb1
3 changed files with 22 additions and 6 deletions
20
filelist.go
20
filelist.go
|
@ -57,14 +57,24 @@ func (f *fileList) Set(path string) error {
|
|||
|
||||
func (f fileList) Contains(path string) bool {
|
||||
for p := range f.patterns {
|
||||
if glob.Glob(p, path) {
|
||||
if logger != nil {
|
||||
logger.Printf("skipping: %s\n", path)
|
||||
if strings.Contains(p, glob.GLOB) {
|
||||
if glob.Glob(p, path) {
|
||||
if logger != nil {
|
||||
logger.Printf("skipping: %s\n", path)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
// check if only a sub-folder of the path is excluded
|
||||
if strings.Contains(path, p) {
|
||||
if logger != nil {
|
||||
logger.Printf("skipping: %s\n", path)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//log.Printf("including: %s\n", path)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -235,6 +235,12 @@ func Test_fileList_Contains(t *testing.T) {
|
|||
args: args{path: "/baz/bar/foo_test.go"},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "sub-folder, match",
|
||||
fields: fields{patterns: []string{"vendor"}},
|
||||
args: args{path: "/baz/vendor/bar/foo_test.go"},
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
f := newFileList(tt.fields.patterns...)
|
||||
|
|
2
main.go
2
main.go
|
@ -155,7 +155,7 @@ func main() {
|
|||
|
||||
// Exclude files
|
||||
excluded := newFileList("*_test.go")
|
||||
flag.Var(excluded, "skip", "File pattern to exclude from scan. Uses simple * globs and requires full match")
|
||||
flag.Var(excluded, "skip", "File pattern to exclude from scan. Uses simple * globs and requires full or partial match")
|
||||
|
||||
incRules := ""
|
||||
flag.StringVar(&incRules, "include", "", "Comma separated list of rules IDs to include. (see rule list)")
|
||||
|
|
Loading…
Reference in a new issue