Repository: python-telegram-bot/python-telegram-bot

Issue:
Commands and \n after aren't processed by CommandHandler
<!--
Thanks for reporting issues of python-telegram-bot!

Use this template to notify us if you found a bug, or if you want to request a new feature.
If you're looking for help with programming your bot using our library, feel free to ask your
questions in out telegram group at: https://t.me/pythontelegrambotgroup

To make it easier for us to help you please enter detailed information below.

Please note, we only support the latest version of python-telegram-bot and
master branch. Please make sure to upgrade & recreate the issue on the latest
version prior to opening an issue.
-->
### Steps to reproduce
1. Make a bot with a CommandHandler

2. Send a command with \n after it without space! Like this:
```
/feedback
some text
```

### Expected behaviour
Command should not be ignored...

### Actual behaviour
...but it is ignored instead

### Configuration
**Operating System:**
Gentoo

**Version of Python, python-telegram-bot & dependencies:**

``$ python -m telegram``
```
Traceback (most recent call last):
  File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/kisik21/Projects/Nadeko/.virtualenv/lib64/python3.6/site-packages/telegram/__main__.py", line 3, in <module>
    import urllib3
ModuleNotFoundError: No module named 'urllib3'
```
Okay, I installed urllib3...
```
python-telegram-bot 6.1.0
urllib3 1.22
certifi 2017.04.17
future 0.16.0
Python 3.6.1 (default, Sep 25 2017, 22:51:25)  [GCC 5.4.0]
```
### Logs
Don't think this applies here.

The issue is probably the CommandHandler - I read the code, it thinks of \n as a part of command string. We need to strip these while detecting command names, I think...


Discussion:
Hi,

Thanks for reporting this. We will take action soon.


Resolving patch:
diff --git a/telegram/ext/commandhandler.py b/telegram/ext/commandhandler.py
--- a/telegram/ext/commandhandler.py
+++ b/telegram/ext/commandhandler.py
@@ -134,7 +134,7 @@ def check_update(self, update):
             message = update.message or update.edited_message
 
             if message.text:
-                command = message.text[1:].split(' ')[0].split('@')
+                command = message.text[1:].split(None, 1)[0].split('@')
                 command.append(
                     message.bot.username)  # in case the command was send without a username
 


Test patch:
diff --git a/tests/test_commandhandler.py b/tests/test_commandhandler.py
--- a/tests/test_commandhandler.py
+++ b/tests/test_commandhandler.py
@@ -165,6 +165,15 @@ def test_pass_args(self, dp, message):
         dp.process_update(Update(0, message=message))
         assert self.test_flag
 
+    def test_newline(self, dp, message):
+        handler = CommandHandler('test', self.callback_basic)
+        dp.add_handler(handler)
+
+        message.text = '/test\nfoobar'
+        assert handler.check_update(Update(0, message))
+        dp.process_update(Update(0, message))
+        assert self.test_flag
+
     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)