From 0611d0d953828f237debab9efea8dfc166dbde78 Mon Sep 17 00:00:00 2001 From: Temrjan Date: Sat, 4 Apr 2026 03:27:29 +0500 Subject: [PATCH] fix: CommandStart(deep_link=False) now rejects deep-link arguments (#1790) Previously the deep_link parameter only had two effective states: False (default) accepted any /start command regardless of arguments, and True required arguments to be present. Change the default to None (accept both, backward compatible) so that False can mean "reject if deep-link arguments are present", which is the intuitive expectation when explicitly passing deep_link=False. Closes #1713 Co-authored-by: Claude Opus 4.6 (1M context) --- CHANGES/1713.bugfix.rst | 1 + aiogram/filters/command.py | 9 +++++++-- tests/test_filters/test_command.py | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 CHANGES/1713.bugfix.rst diff --git a/CHANGES/1713.bugfix.rst b/CHANGES/1713.bugfix.rst new file mode 100644 index 00000000..51c6a4d5 --- /dev/null +++ b/CHANGES/1713.bugfix.rst @@ -0,0 +1 @@ +``CommandStart(deep_link=False)`` now correctly rejects messages that contain deep-link arguments. Previously ``deep_link=False`` (the default) did not distinguish between ``/start`` and ``/start ``. The default is changed to ``None`` (accept both) to preserve backward compatibility. diff --git a/aiogram/filters/command.py b/aiogram/filters/command.py index 498cd8c7..ecb03c48 100644 --- a/aiogram/filters/command.py +++ b/aiogram/filters/command.py @@ -240,7 +240,7 @@ class CommandObject: class CommandStart(Command): def __init__( self, - deep_link: bool = False, + deep_link: bool | None = None, deep_link_encoded: bool = False, ignore_case: bool = False, ignore_mention: bool = False, @@ -282,7 +282,12 @@ class CommandStart(Command): return command # noqa: RET504 def validate_deeplink(self, command: CommandObject) -> CommandObject: - if not self.deep_link: + if self.deep_link is None: + return command + if self.deep_link is False: + if command.args: + msg = "Deep-link was not expected" + raise CommandException(msg) return command if not command.args: msg = "Deep-link was missing" diff --git a/tests/test_filters/test_command.py b/tests/test_filters/test_command.py index ec79098a..2c01e151 100644 --- a/tests/test_filters/test_command.py +++ b/tests/test_filters/test_command.py @@ -85,6 +85,9 @@ class TestCommandFilter: False, ], ["/start test", CommandStart(), True], + ["/start", CommandStart(), True], + ["/start", CommandStart(deep_link=False), True], + ["/start test", CommandStart(deep_link=False), False], ["/start", CommandStart(deep_link=True), False], ["/start test", CommandStart(deep_link=True), True], ["/start test", CommandStart(deep_link=True, deep_link_encoded=True), False], @@ -175,7 +178,7 @@ class TestCommandStart: cmd = CommandStart() assert ( str(cmd) - == "CommandStart(ignore_case=False, ignore_mention=False, deep_link=False, deep_link_encoded=False)" + == "CommandStart(ignore_case=False, ignore_mention=False, deep_link_encoded=False)" )