Skip to content

Commit

Permalink
Don't ignore newlines when filtering invites (#3207)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaruh authored Nov 27, 2024
1 parent f229e5f commit 16441a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bot/exts/filtering/_filter_lists/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def actions_for(
self, ctx: FilterContext
) -> tuple[ActionSettings | None, list[str], dict[ListType, list[Filter]]]:
"""Dispatch the given event to the list's filters, and return actions to take and messages to relay to mods."""
text = clean_input(ctx.content)
text = clean_input(ctx.content, keep_newlines=True)

matches = list(DISCORD_INVITE.finditer(text))
invite_codes = {m.group("invite") for m in matches}
Expand Down
6 changes: 3 additions & 3 deletions bot/exts/filtering/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def subclasses_in_package(package: str, prefix: str, parent: T) -> set[T]:
return subclasses


def clean_input(string: str) -> str:
def clean_input(string: str, *, keep_newlines: bool = False) -> str:
"""Remove zalgo and invisible characters from `string`."""
# For future consideration: remove characters in the Mc, Sk, and Lm categories too.
# Can be normalised with form C to merge char + combining char into a single char to avoid
Expand All @@ -60,8 +60,8 @@ def clean_input(string: str) -> str:

# URL quoted strings can be used to hide links to servers
content = urllib.parse.unquote(content)
# Drop newlines that can be used to bypass filter
content = content.replace("\n", "")
if not keep_newlines: # Drop newlines that can be used to bypass filter
content = content.replace("\n", "")
# Avoid escape characters
content = content.replace("\\", "")

Expand Down

0 comments on commit 16441a1

Please sign in to comment.