Merge pull request #867 from projectdiscovery/fix-filter-exclude-issue

Fixed filter exclude issue
dev
Sandeep Singh 2021-07-26 17:04:21 +05:30 committed by GitHub
commit 25be233e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 16 deletions

View File

@ -29,10 +29,9 @@ func (t *TagFilter) Match(tag, author, severity string) (bool, error) {
matchedAny := false
if len(t.allowedTags) > 0 {
_, ok := t.allowedTags[tag]
if !ok {
return false, nil
if ok {
matchedAny = true
}
matchedAny = true
}
_, ok := t.block[tag]
if ok {
@ -76,10 +75,9 @@ func (t *TagFilter) MatchWithAllowedTags(allowed []string, tag, author, severity
}
if len(allowedMap) > 0 {
_, ok := allowedMap[tag]
if !ok {
return false, nil
if ok {
matchedAny = true
}
matchedAny = true
}
_, ok := t.block[tag]
if ok && !matchedAny {

View File

@ -40,16 +40,6 @@ func TestTagBasedFilter(t *testing.T) {
require.Nil(t, err, "could not get match")
require.True(t, matched, "could not get correct match")
})
t.Run("match-includes", func(t *testing.T) {
config := &Config{
Tags: []string{"fuzz"},
ExcludeTags: []string{"fuzz"},
}
filter := New(config)
matched, err := filter.Match("fuzz", "pdteam", "low")
require.Nil(t, err, "could not get match")
require.True(t, matched, "could not get correct match")
})
t.Run("match-author", func(t *testing.T) {
config := &Config{
Authors: []string{"pdteam"},
@ -66,6 +56,15 @@ func TestTagBasedFilter(t *testing.T) {
matched, _ := filter.Match("fuzz", "pdteam", "high")
require.True(t, matched, "could not get correct match")
})
t.Run("match-exclude-with-tags", func(t *testing.T) {
config := &Config{
Tags: []string{"tag"},
ExcludeTags: []string{"another"},
}
filter := New(config)
matched, _ := filter.Match("another", "pdteam", "high")
require.False(t, matched, "could not get correct match")
})
t.Run("match-conditions", func(t *testing.T) {
config := &Config{
Authors: []string{"pdteam"},