diff --git a/CHANGES.rst b/CHANGES.rst index 832a06a3c..4ca8f4171 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,6 +18,7 @@ fixes: - chore: bump jinja2 to 3.1.5 and requests to 2.32.0 (#1714) - Fix: situationally broken apropos command (#1711) - chore: bump requests to 2.32.3 (#1715) +- Fix: Newlines replaced with spaces in botcmd args (#1716) - chore: bump jinja2 to 3.1.6 (#1723) - chore: update errbot-backend-slackv3 version to 0.3.1 (#1725) diff --git a/errbot/core.py b/errbot/core.py index aee5a160e..7dd9d9ee2 100644 --- a/errbot/core.py +++ b/errbot/core.py @@ -325,21 +325,25 @@ def process_message(self, msg: Message) -> bool: prefixed = True text = text.strip() - text_split = text.split() cmd = None command = None args = "" if not only_check_re_command: - i = len(text_split) + first = True + i = len(text.split()) while cmd is None: + # maxsplit so we can preserve linebreaks and other whitespace in args + text_split = text.split(maxsplit=i) command = "_".join(text_split[:i]) with self._gbl: if command in self.commands: cmd = command - args = " ".join(text_split[i:]) + if not first: + args = text_split[-1] else: i -= 1 + first = False if i <= 0: break diff --git a/tests/commands_test.py b/tests/commands_test.py index f3cdbc5a7..202349c88 100644 --- a/tests/commands_test.py +++ b/tests/commands_test.py @@ -57,6 +57,16 @@ def test_echo(testbot): assert "foo" in testbot.exec_command("!echo foo") +def test_echo_newline_args(testbot): + # https://github.com/errbotio/errbot/issues/1307 + assert testbot.exec_command("!echo\nfoo\nbar").startswith("foo") + + +def test_echo_newline_preserved(testbot): + # https://github.com/errbotio/errbot/issues/1716 + assert "\n" in testbot.exec_command("!echo foo\nbar") + + def test_status_gc(testbot): assert "GC 0->" in testbot.exec_command("!status gc")