diff --git a/internal/domain/filter.go b/internal/domain/filter.go index 7191ba1..d3d2f46 100644 --- a/internal/domain/filter.go +++ b/internal/domain/filter.go @@ -388,18 +388,18 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) { } if f.Tags != "" { - if f.TagsMatchLogic == "ANY" && !containsAny(r.Tags, f.Tags) { - r.addRejectionF("tags not matching. got: %v want: %v", r.Tags, f.Tags) - } else if f.TagsMatchLogic == "ALL" && !containsAll(r.Tags, f.Tags) { + if f.TagsMatchLogic == "ALL" && !containsAll(r.Tags, f.Tags) { r.addRejectionF("tags not matching. got: %v want(all): %v", r.Tags, f.Tags) + } else if !containsAny(r.Tags, f.Tags) { // TagsMatchLogic is set to "" by default, this makes sure that "" and "ANY" are treated the same way. + r.addRejectionF("tags not matching. got: %v want: %v", r.Tags, f.Tags) } } if f.ExceptTags != "" { - if f.ExceptTagsMatchLogic == "ANY" && containsAny(r.Tags, f.ExceptTags) { - r.addRejectionF("tags unwanted. got: %v want: %v", r.Tags, f.ExceptTags) - } else if f.ExceptTagsMatchLogic == "ALL" && containsAll(r.Tags, f.ExceptTags) { - r.addRejectionF("tags unwanted. got: %v want(all): %v", r.Tags, f.ExceptTags) + if f.ExceptTagsMatchLogic == "ALL" && containsAll(r.Tags, f.ExceptTags) { + r.addRejectionF("tags unwanted. got: %v don't want: %v", r.Tags, f.ExceptTags) + } else if containsAny(r.Tags, f.ExceptTags) { // ExceptTagsMatchLogic is set to "" by default, this makes sure that "" and "ANY" are treated the same way. + r.addRejectionF("tags unwanted. got: %v don't want: %v", r.Tags, f.ExceptTags) } } @@ -683,6 +683,7 @@ func containsMatch(tags []string, filters []string) bool { continue } tag = strings.ToLower(tag) + tag = strings.Trim(tag, " ") for _, filter := range filters { if filter == "" { @@ -720,6 +721,7 @@ func containsAllMatch(tags []string, filters []string) bool { continue } tag = strings.ToLower(tag) + tag = strings.Trim(tag, " ") if tag == filter { found = true diff --git a/internal/domain/filter_test.go b/internal/domain/filter_test.go index 46bf02b..b534956 100644 --- a/internal/domain/filter_test.go +++ b/internal/domain/filter_test.go @@ -522,6 +522,27 @@ func TestFilter_CheckFilter(t *testing.T) { }, want: true, }, + { + name: "match_tags_empty", + fields: &Release{ + TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2", + Category: "TV", + Uploader: "Uploader1", + Tags: []string{"tv"}, + }, + args: args{ + filter: Filter{ + Enabled: true, + MatchCategories: "*tv*", + MatchUploaders: "Uploader1,Uploader2", + ExceptUploaders: "Anonymous", + Shows: "Good show", + Tags: "tv", + TagsMatchLogic: "", + }, + }, + want: true, + }, { name: "match_tags_any", fields: &Release{ @@ -647,8 +668,9 @@ func TestFilter_CheckFilter(t *testing.T) { ExceptTags: "tv,foreign", TagsMatchLogic: "ALL", }, + rejections: []string{"tags unwanted. got: [foreign] don't want: tv,foreign"}, }, - want: true, + want: false, }, { name: "match_except_tags_any_2", @@ -668,7 +690,7 @@ func TestFilter_CheckFilter(t *testing.T) { ExceptTags: "foreign", ExceptTagsMatchLogic: "ANY", }, - rejections: []string{"tags unwanted. got: [foreign] want: foreign"}, + rejections: []string{"tags unwanted. got: [foreign] don't want: foreign"}, }, want: false, }, @@ -690,7 +712,7 @@ func TestFilter_CheckFilter(t *testing.T) { ExceptTags: "foreign,tv", ExceptTagsMatchLogic: "ALL", }, - rejections: []string{"tags unwanted. got: [tv foreign] want(all): foreign,tv"}, + rejections: []string{"tags unwanted. got: [tv foreign] don't want: foreign,tv"}, }, want: false, },