Fix for crashes on 8.1 (#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
This commit is contained in:
Jacob Bom 2017-10-15 16:59:10 +02:00 committed by Eldinnie
parent 23774383dc
commit 8df35fd53b
5 changed files with 28 additions and 5 deletions

View file

@ -1,7 +1,14 @@
=======
Changes
=======
**2010-10-14**
**2017-10-15**
*Released 8.1.1*
- Fix Commandhandler crashing on single character messages (PR `#873`_).
.. _`#873`: https://github.com/python-telegram-bot/python-telegram-bot/pull/871
**2017-10-14**
*Released 8.1.0*
New features

View file

@ -60,7 +60,7 @@ author = u'Leandro Toledo'
# The short X.Y version.
version = '8.1' # telegram.__version__[:3]
# The full version, including alpha/beta/rc tags.
release = '8.1.0' # telegram.__version__
release = '8.1.1' # telegram.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View file

@ -133,7 +133,7 @@ class CommandHandler(Handler):
and (update.message or update.edited_message and self.allow_edited)):
message = update.message or update.edited_message
if message.text:
if message.text and message.text.startswith('/') and len(message.text) > 1:
command = message.text[1:].split(None, 1)[0].split('@')
command.append(
message.bot.username) # in case the command was send without a username
@ -145,7 +145,7 @@ class CommandHandler(Handler):
else:
res = self.filters(message)
return res and (message.text.startswith('/') and command[0].lower() in self.command
return res and (command[0].lower() in self.command
and command[1].lower() == message.bot.username.lower())
else:
return False

View file

@ -17,4 +17,4 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
__version__ = '8.1.0'
__version__ = '8.1.1'

View file

@ -174,6 +174,22 @@ class TestCommandHandler(object):
dp.process_update(Update(0, message))
assert self.test_flag
def test_single_char(self, dp, message):
# Regression test for https://github.com/python-telegram-bot/python-telegram-bot/issues/871
handler = CommandHandler('test', self.callback_basic)
dp.add_handler(handler)
message.text = 'a'
assert not handler.check_update(Update(0, message))
def test_single_slash(self, dp, message):
# Regression test for https://github.com/python-telegram-bot/python-telegram-bot/issues/871
handler = CommandHandler('test', self.callback_basic)
dp.add_handler(handler)
message.text = '/'
assert not handler.check_update(Update(0, message))
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)