From bbdc43b737d4cefaa7eed2ff3c1971339ecbbd66 Mon Sep 17 00:00:00 2001 From: AmirSoroush Date: Fri, 17 Jan 2025 02:35:23 +0300 Subject: [PATCH] Fix `BAD_PATTERN` regex in deeplinking process. (#1630) * add test payload in `test_deep_linking` to demonstrate the bug * fix the `BAD_PATTERN` regex * add changes file --- CHANGES/1630.bugfix.rst | 1 + aiogram/utils/deep_linking.py | 2 +- tests/test_utils/test_deep_linking.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 CHANGES/1630.bugfix.rst diff --git a/CHANGES/1630.bugfix.rst b/CHANGES/1630.bugfix.rst new file mode 100644 index 00000000..e083dc1f --- /dev/null +++ b/CHANGES/1630.bugfix.rst @@ -0,0 +1 @@ +Fix the regex pattern that finds the "bad characters" for deeplink payload. \ No newline at end of file diff --git a/aiogram/utils/deep_linking.py b/aiogram/utils/deep_linking.py index 19cc64c6..fe2764f7 100644 --- a/aiogram/utils/deep_linking.py +++ b/aiogram/utils/deep_linking.py @@ -18,7 +18,7 @@ from aiogram.utils.payload import decode_payload, encode_payload if TYPE_CHECKING: from aiogram import Bot -BAD_PATTERN = re.compile(r"[^A-z0-9-]") +BAD_PATTERN = re.compile(r"[^a-zA-Z0-9-_]") async def create_start_link( diff --git a/tests/test_utils/test_deep_linking.py b/tests/test_utils/test_deep_linking.py index 85a6027b..c5f5259a 100644 --- a/tests/test_utils/test_deep_linking.py +++ b/tests/test_utils/test_deep_linking.py @@ -10,12 +10,14 @@ PAYLOADS = [ "aaBBccDDeeFF5544332211", -12345678901234567890, 12345678901234567890, + "underscore_and-dash", ] WRONG_PAYLOADS = [ "@BotFather", "Some:special$characters#=", "spaces spaces spaces", 1234567890123456789.0, + "has`backtick", ]