Skip to content

Commit ec9b16a

Browse files
jh0kertsnoam
authored andcommitted
Fix command not recognized if it is directly followed by a newline (python-telegram-bot#869)
fixes python-telegram-bot#868
1 parent bfad2fa commit ec9b16a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

telegram/ext/commandhandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def check_update(self, update):
134134
message = update.message or update.edited_message
135135

136136
if message.text:
137-
command = message.text[1:].split(' ')[0].split('@')
137+
command = message.text[1:].split(None, 1)[0].split('@')
138138
command.append(
139139
message.bot.username) # in case the command was send without a username
140140

tests/test_commandhandler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ def test_pass_args(self, dp, message):
165165
dp.process_update(Update(0, message=message))
166166
assert self.test_flag
167167

168+
def test_newline(self, dp, message):
169+
handler = CommandHandler('test', self.callback_basic)
170+
dp.add_handler(handler)
171+
172+
message.text = '/test\nfoobar'
173+
assert handler.check_update(Update(0, message))
174+
dp.process_update(Update(0, message))
175+
assert self.test_flag
176+
168177
def test_pass_user_or_chat_data(self, dp, message):
169178
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
170179
dp.add_handler(handler)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy