Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ignore newlines when filtering invites #3207

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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