aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Boris Muratov <[email protected]>2024-11-27 21:04:12 +0200
committerGravatar GitHub <[email protected]>2024-11-27 19:04:12 +0000
commit16441a1acd1e3be3d3e9a7294bee5a0468b86356 (patch)
treef3c91ce68a7d8ee2d9d67c0576104cce178a8570
parentBump pydis-core to 11.5.1 (diff)
Don't ignore newlines when filtering invites (#3207)
-rw-r--r--bot/exts/filtering/_filter_lists/invite.py2
-rw-r--r--bot/exts/filtering/_utils.py6
2 files changed, 4 insertions, 4 deletions
diff --git a/bot/exts/filtering/_filter_lists/invite.py b/bot/exts/filtering/_filter_lists/invite.py
index 669281818..9a693f1a3 100644
--- a/bot/exts/filtering/_filter_lists/invite.py
+++ b/bot/exts/filtering/_filter_lists/invite.py
@@ -60,7 +60,7 @@ class InviteList(FilterList[InviteFilter]):
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}
diff --git a/bot/exts/filtering/_utils.py b/bot/exts/filtering/_utils.py
index 9861f9ddc..73974881a 100644
--- a/bot/exts/filtering/_utils.py
+++ b/bot/exts/filtering/_utils.py
@@ -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
@@ -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("\\", "")