Skip to content

Commit 8df35fd

Browse files
jsmnbomEldinnie
authored andcommitted
Fix for crashes on 8.1 (python-telegram-bot#873)
* Make Commandhandler not crash on single char messages * Bump release and update CHANGES.rst for 8.1.1 * No error on single / and test
1 parent 2377438 commit 8df35fd

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

CHANGES.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
=======
22
Changes
33
=======
4-
**2010-10-14**
4+
**2017-10-15**
5+
*Released 8.1.1*
6+
7+
- Fix Commandhandler crashing on single character messages (PR `#873`_).
8+
9+
.. _`#873`: https://github.com/python-telegram-bot/python-telegram-bot/pull/871
10+
11+
**2017-10-14**
512
*Released 8.1.0*
613

714
New features

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# The short X.Y version.
6161
version = '8.1' # telegram.__version__[:3]
6262
# The full version, including alpha/beta/rc tags.
63-
release = '8.1.0' # telegram.__version__
63+
release = '8.1.1' # telegram.__version__
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

telegram/ext/commandhandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def check_update(self, update):
133133
and (update.message or update.edited_message and self.allow_edited)):
134134
message = update.message or update.edited_message
135135

136-
if message.text:
136+
if message.text and message.text.startswith('/') and len(message.text) > 1:
137137
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
@@ -145,7 +145,7 @@ def check_update(self, update):
145145
else:
146146
res = self.filters(message)
147147

148-
return res and (message.text.startswith('/') and command[0].lower() in self.command
148+
return res and (command[0].lower() in self.command
149149
and command[1].lower() == message.bot.username.lower())
150150
else:
151151
return False

telegram/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
1919

20-
__version__ = '8.1.0'
20+
__version__ = '8.1.1'

tests/test_commandhandler.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ def test_newline(self, dp, message):
174174
dp.process_update(Update(0, message))
175175
assert self.test_flag
176176

177+
def test_single_char(self, dp, message):
178+
# Regression test for https://github.com/python-telegram-bot/python-telegram-bot/issues/871
179+
handler = CommandHandler('test', self.callback_basic)
180+
dp.add_handler(handler)
181+
182+
message.text = 'a'
183+
assert not handler.check_update(Update(0, message))
184+
185+
def test_single_slash(self, dp, message):
186+
# Regression test for https://github.com/python-telegram-bot/python-telegram-bot/issues/871
187+
handler = CommandHandler('test', self.callback_basic)
188+
dp.add_handler(handler)
189+
190+
message.text = '/'
191+
assert not handler.check_update(Update(0, message))
192+
177193
def test_pass_user_or_chat_data(self, dp, message):
178194
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
179195
dp.add_handler(handler)

0 commit comments

Comments
 (0)