diff --git a/v2/pkg/catalog/loader/filter/tag_filter.go b/v2/pkg/catalog/loader/filter/tag_filter.go index bd23de16..59c81d74 100644 --- a/v2/pkg/catalog/loader/filter/tag_filter.go +++ b/v2/pkg/catalog/loader/filter/tag_filter.go @@ -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 { diff --git a/v2/pkg/catalog/loader/filter/tag_filter_test.go b/v2/pkg/catalog/loader/filter/tag_filter_test.go index f26b1b9f..6eb36177 100644 --- a/v2/pkg/catalog/loader/filter/tag_filter_test.go +++ b/v2/pkg/catalog/loader/filter/tag_filter_test.go @@ -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"},