mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fixed #1013: Empty mention should be None instead of empty string.
This commit is contained in:
parent
5c218d7983
commit
02357faf03
3 changed files with 22 additions and 1 deletions
1
CHANGES/1013.bugfix.rst
Normal file
1
CHANGES/1013.bugfix.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fixed empty mention in command parsing, now it will be None instead of an empty string
|
||||
|
|
@ -132,7 +132,10 @@ class Command(Filter):
|
|||
# "/command@mention" -> "/", ("command", "@", "mention")
|
||||
prefix, (command, _, mention) = full_command[0], full_command[1:].partition("@")
|
||||
return CommandObject(
|
||||
prefix=prefix, command=command, mention=mention, args=args[0] if args else None
|
||||
prefix=prefix,
|
||||
command=command,
|
||||
mention=mention or None,
|
||||
args=args[0] if args else None,
|
||||
)
|
||||
|
||||
def validate_prefix(self, command: CommandObject) -> None:
|
||||
|
|
|
|||
|
|
@ -104,6 +104,23 @@ class TestCommandFilter:
|
|||
assert "args" in result
|
||||
assert result["args"] == "42"
|
||||
|
||||
async def test_empty_mention_is_none(self, bot: MockedBot):
|
||||
# Fixed https://github.com/aiogram/aiogram/issues/1013:
|
||||
# Empty mention should be None instead of empty string.
|
||||
|
||||
message = Message(
|
||||
message_id=0,
|
||||
text="/test",
|
||||
chat=Chat(id=42, type="private"),
|
||||
date=datetime.datetime.now(),
|
||||
)
|
||||
command = Command("test")
|
||||
result = await command(message=message, bot=bot)
|
||||
|
||||
assert "command" in result
|
||||
command_obj: CommandObject = result["command"]
|
||||
assert command_obj.mention is None
|
||||
|
||||
|
||||
class TestCommandObject:
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue