diff --git a/docs/changelog.rst b/docs/changelog.rst index 311850e5d..cb5d8e705 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,9 @@ Changelog ========= +- :release:`11.7.0 <10th August 2025>` +- :bug:`304` Update Discord invite regex to handle new protocol. + - :release:`11.6.1 <13th July 2025>` - :bug:`303` Update Discord invite regex to handle cases with additional slashes. diff --git a/pydis_core/utils/regex.py b/pydis_core/utils/regex.py index ba6b9b01b..26b1a547b 100644 --- a/pydis_core/utils/regex.py +++ b/pydis_core/utils/regex.py @@ -3,14 +3,16 @@ import re DISCORD_INVITE = re.compile( - r"(https?:\/\/)?(www\.)?" # Optional http(s) and www. + r"(https?:\/\/)?(discord:\/*)?" # Optional protocols + r"(www\.)?" # Optional www + r"[@#]*" # Optional @ or # symbols r"(\B|discord(app)?)" # Optional discord(app) r"([.,]|dot)" # Various characters to cover dots r"(" r"(gg|me)" # TLDs that embed within discord r"|com(\/|slash|\\)invite" # Only match com/invite r")" - r"(/|slash|\\+)" # / or 'slash' or 1+ of \ + r"(/|slash|\\+)" # / or 'slash' or 1+ of \ r"(?P\S+)", # the invite code itself flags=re.IGNORECASE ) diff --git a/pyproject.toml b/pyproject.toml index 727f6e9c1..ed1ed117c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pydis_core" -version = "11.6.1" +version = "11.7.0" description = "PyDis core provides core functionality and utility to the bots of the Python Discord community." authors = ["Python Discord "] license = "MIT" diff --git a/tests/pydis_core/utils/test_regex.py b/tests/pydis_core/utils/test_regex.py index 79c1d7436..26fe23ea6 100644 --- a/tests/pydis_core/utils/test_regex.py +++ b/tests/pydis_core/utils/test_regex.py @@ -49,6 +49,11 @@ def test_discord_invite_positives(self): self.assertEqual(search_regex("https://discord.gg/python with whitespace"), "python") self.assertEqual(search_regex(" https://discord.gg/python "), "python") + self.assertEqual(search_regex("discord:#@discordapp.com/invite/python"), "python") + self.assertEqual(search_regex("discord:/#@discordapp.com/invite/python"), "python") + self.assertEqual(search_regex("discord://#@discordapp.com/invite/python"), "python") + self.assertEqual(search_regex("discord://@#discordapp.com/invite/python"), "python") + def test_discord_invite_negatives(self): """Test the DISCORD_INVITE regex on a set of strings we would expect to not capture."""