Skip to content

Commit fd70e41

Browse files
zaughonMartin Flygenringsijis
authored
Fix: Newlines replaced with spaces in botcmd args (#1716) (#1717)
* Fix: Newlines replaced with spaces in botcmd args (#1716) * Added command tests for #1307 and #1716 --------- Co-authored-by: Martin Flygenring <[email protected]> Co-authored-by: Sijis Aviles <[email protected]>
1 parent 3c3af1a commit fd70e41

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fixes:
1818
- chore: bump jinja2 to 3.1.5 and requests to 2.32.0 (#1714)
1919
- Fix: situationally broken apropos command (#1711)
2020
- chore: bump requests to 2.32.3 (#1715)
21+
- Fix: Newlines replaced with spaces in botcmd args (#1716)
2122
- chore: bump jinja2 to 3.1.6 (#1723)
2223
- chore: update errbot-backend-slackv3 version to 0.3.1 (#1725)
2324

errbot/core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,25 @@ def process_message(self, msg: Message) -> bool:
325325
prefixed = True
326326

327327
text = text.strip()
328-
text_split = text.split()
329328
cmd = None
330329
command = None
331330
args = ""
332331
if not only_check_re_command:
333-
i = len(text_split)
332+
first = True
333+
i = len(text.split())
334334
while cmd is None:
335+
# maxsplit so we can preserve linebreaks and other whitespace in args
336+
text_split = text.split(maxsplit=i)
335337
command = "_".join(text_split[:i])
336338

337339
with self._gbl:
338340
if command in self.commands:
339341
cmd = command
340-
args = " ".join(text_split[i:])
342+
if not first:
343+
args = text_split[-1]
341344
else:
342345
i -= 1
346+
first = False
343347
if i <= 0:
344348
break
345349

tests/commands_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ def test_echo(testbot):
5757
assert "foo" in testbot.exec_command("!echo foo")
5858

5959

60+
def test_echo_newline_args(testbot):
61+
# https://github.com/errbotio/errbot/issues/1307
62+
assert testbot.exec_command("!echo\nfoo\nbar").startswith("foo")
63+
64+
65+
def test_echo_newline_preserved(testbot):
66+
# https://github.com/errbotio/errbot/issues/1716
67+
assert "\n" in testbot.exec_command("!echo foo\nbar")
68+
69+
6070
def test_status_gc(testbot):
6171
assert "GC 0->" in testbot.exec_command("!status gc")
6272

0 commit comments

Comments
 (0)