Fix command not recognized if it is directly followed by a newline (#869)

fixes #868
This commit is contained in:
Jannes Höke 2017-10-14 20:04:02 +02:00 committed by Noam Meltzer
parent bfad2fa1f3
commit ec9b16ac7b
2 changed files with 10 additions and 1 deletions

View file

@ -134,7 +134,7 @@ class CommandHandler(Handler):
message = update.message or update.edited_message
if message.text:
command = message.text[1:].split(' ')[0].split('@')
command = message.text[1:].split(None, 1)[0].split('@')
command.append(
message.bot.username) # in case the command was send without a username

View file

@ -165,6 +165,15 @@ class TestCommandHandler(object):
dp.process_update(Update(0, message=message))
assert self.test_flag
def test_newline(self, dp, message):
handler = CommandHandler('test', self.callback_basic)
dp.add_handler(handler)
message.text = '/test\nfoobar'
assert handler.check_update(Update(0, message))
dp.process_update(Update(0, message))
assert self.test_flag
def test_pass_user_or_chat_data(self, dp, message):
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
dp.add_handler(handler)