Skip to content

Commit a91fe5f

Browse files
eligaojh0ker
authored andcommitted
Properly split and handle arguments in CommandHandler (python-telegram-bot#414)
* Properly split and handle arguments in CommandHandler * Update the docstring for pass_args in CommandHandler * Properly split and handle arguments in StringCommandHandler
1 parent 5116a77 commit a91fe5f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The following wonderful people contributed directly or indirectly to this projec
1111
- `Avanatiker <https://github.com/Avanatiker>`_
1212
- `Balduro <https://github.com/Balduro>`_
1313
- `bimmlerd <https://github.com/bimmlerd>`_
14+
- `Eli Gao <https://github.com/eligao>`_
1415
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
1516
- `franciscod <https://github.com/franciscod>`_
1617
- `Jacob Bom <https://github.com/bomjacob>`_

telegram/ext/commandhandler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class CommandHandler(Handler):
3939
pass_args (optional[bool]): If the handler should be passed the
4040
arguments passed to the command as a keyword argument called `
4141
``args``. It will contain a list of strings, which is the text
42-
following the command split on spaces. Default is ``False``
42+
following the command split on single or consecutive whitespace characters.
43+
Default is ``False``
4344
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
4445
``update_queue`` will be passed to the callback function. It will be the ``Queue``
4546
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
@@ -80,7 +81,7 @@ def handle_update(self, update, dispatcher):
8081
message = update.message or update.edited_message
8182

8283
if self.pass_args:
83-
optional_args['args'] = message.text.split(' ')[1:]
84+
optional_args['args'] = message.text.split()[1:]
8485

8586
return self.callback(dispatcher.bot, update, **optional_args)
8687

telegram/ext/stringcommandhandler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class StringCommandHandler(Handler):
3535
pass_args (optional[bool]): If the handler should be passed the
3636
arguments passed to the command as a keyword argument called `
3737
``args``. It will contain a list of strings, which is the text
38-
following the command split on spaces. Default is ``False``
38+
following the command split on single or consecutive whitespace characters.
39+
Default is ``False``
3940
pass_update_queue (optional[bool]): If set to ``True``, a keyword argument called
4041
``update_queue`` will be passed to the callback function. It will be the ``Queue``
4142
instance used by the ``Updater`` and ``Dispatcher`` that contains new updates which can
@@ -65,7 +66,7 @@ def handle_update(self, update, dispatcher):
6566
optional_args = self.collect_optional_args(dispatcher)
6667

6768
if self.pass_args:
68-
optional_args['args'] = update.split(' ')[1:]
69+
optional_args['args'] = update.split()[1:]
6970

7071
return self.callback(dispatcher.bot, update, **optional_args)
7172

0 commit comments

Comments
 (0)