Skip to content

Commit

Permalink
Option to force leading whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Xnero committed Feb 22, 2021
1 parent 59c31c0 commit b277c36
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions chatcommands.py
Expand Up @@ -358,8 +358,10 @@ def do_blacklist(blacklist_type, msg, force=False):
append_force_to_do = "; append `-force` if you really want to do that."

pattern = get_pattern_from_content_source(msg)
# Remove any leading whitespaces
pattern = regex.sub(r"^\s*", "", pattern)

has_leading_whitespace = ""
if regex.search(r"^\s*", "", pattern):
has_leading_whitespace = "The regex contains a leading whitespace character."
has_u202d = ""
if '\u202d' in pattern:
has_u202d = (
Expand Down Expand Up @@ -398,12 +400,17 @@ def do_blacklist(blacklist_type, msg, force=False):
concretized_pattern, is_username=username, is_watchlist=is_watchlist, is_phone=is_phone)

if reasons:
has_leading_whitespace = "; in addition, " + has_leading_whitespace.lower() \
if has_leading_whitespace else ""
has_u202d = "; in addition, " + has_u202d.lower() if has_u202d else ""
has_unescaped_dot = "; in addition, " + has_unescaped_dot.lower() if has_unescaped_dot else ""
raise CmdException(
"That pattern looks like it's already caught by " +
format_blacklist_reasons(reasons) + has_unescaped_dot + has_u202d + append_force_to_do)

if has_leading_whitespace:
raise CmdException(has_leading_whitespace + append_force_to_do)

if has_u202d:
raise CmdException(has_u202d + has_unescaped_dot + append_force_to_do)

Expand Down

0 comments on commit b277c36

Please sign in to comment.