mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-31 16:40:53 +01:00
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:
parent
23774383dc
commit
8df35fd53b
5 changed files with 28 additions and 5 deletions
|
@ -1,7 +1,14 @@
|
||||||
=======
|
=======
|
||||||
Changes
|
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*
|
*Released 8.1.0*
|
||||||
|
|
||||||
New features
|
New features
|
||||||
|
|
|
@ -60,7 +60,7 @@ author = u'Leandro Toledo'
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = '8.1' # telegram.__version__[:3]
|
version = '8.1' # telegram.__version__[:3]
|
||||||
# The full version, including alpha/beta/rc tags.
|
# 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
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
|
|
@ -133,7 +133,7 @@ class CommandHandler(Handler):
|
||||||
and (update.message or update.edited_message and self.allow_edited)):
|
and (update.message or update.edited_message and self.allow_edited)):
|
||||||
message = update.message or update.edited_message
|
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 = message.text[1:].split(None, 1)[0].split('@')
|
||||||
command.append(
|
command.append(
|
||||||
message.bot.username) # in case the command was send without a username
|
message.bot.username) # in case the command was send without a username
|
||||||
|
@ -145,7 +145,7 @@ class CommandHandler(Handler):
|
||||||
else:
|
else:
|
||||||
res = self.filters(message)
|
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())
|
and command[1].lower() == message.bot.username.lower())
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -17,4 +17,4 @@
|
||||||
# You should have received a copy of the GNU Lesser Public License
|
# You should have received a copy of the GNU Lesser Public License
|
||||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||||
|
|
||||||
__version__ = '8.1.0'
|
__version__ = '8.1.1'
|
||||||
|
|
|
@ -174,6 +174,22 @@ class TestCommandHandler(object):
|
||||||
dp.process_update(Update(0, message))
|
dp.process_update(Update(0, message))
|
||||||
assert self.test_flag
|
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):
|
def test_pass_user_or_chat_data(self, dp, message):
|
||||||
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
|
handler = CommandHandler('test', self.callback_data_1, pass_user_data=True)
|
||||||
dp.add_handler(handler)
|
dp.add_handler(handler)
|
||||||
|
|
Loading…
Reference in a new issue