fix(filters): handle empty tag_match_logic by defaulting to ANY (#910)

* speculative fix for tags_match_logic if set to ANY

* add default tag match logic handling

* fixed test cases and rejection messages

* trim tags in match funcs

* add test for empty TagsMatchLogic
This commit is contained in:
soup 2023-05-06 16:11:34 +02:00 committed by GitHub
parent 537bbe3394
commit 8a1910843c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 10 deletions

View file

@ -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

View file

@ -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,
},