Make sure not to match all toots if you don't have any filters

This commit is contained in:
Jason McBrayer 2019-02-15 17:14:05 -05:00
parent 3bfbc30255
commit e94eec081a

View File

@ -164,6 +164,8 @@ def get_filters(mastodon, context=None):
return []
def toot_matches_filters(toot, filters=[]):
if not filters:
return False
def maybe_rewrite_filter(filter):
if filter.whole_word:
return f"\\b{filter.phrase}\\b"
@ -171,7 +173,10 @@ def toot_matches_filters(toot, filters=[]):
return filter.phrase
phrases = [maybe_rewrite_filter(x) for x in filters]
pattern = "|".join(phrases)
return re.search(pattern, toot.spoiler_text + toot.content, re.I)
try:
return re.search(pattern, toot.spoiler_text + toot.content, re.I)
except:
return False
###
### View functions