From a82105e09fac7a0d3baaab2396142006a3c70392 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 11 Mar 2020 23:05:11 +0000 Subject: [PATCH] gracefully handle spaces in non-last params (split them) --- irctokens/protocol.py | 7 ++++++- test/format.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/irctokens/protocol.py b/irctokens/protocol.py index cb2421a..723bc16 100644 --- a/irctokens/protocol.py +++ b/irctokens/protocol.py @@ -77,7 +77,12 @@ class Line(object): params = self.params.copy() if self.params: last = params.pop(-1) - outs.extend(params) + for param in params: + if " " in param: + outs.extend(param.split(" ")) + else: + outs.append(param) + if " " in last: last = f":{last}" outs.append(last) diff --git a/test/format.py b/test/format.py index e7b7430..58e243d 100644 --- a/test/format.py +++ b/test/format.py @@ -40,3 +40,8 @@ class FormatTestTrailing(unittest.TestCase): def test_no_space(self): line = irctokens.format("PRIVMSG", ["#channel", "helloworld"]) self.assertEqual(line, "PRIVMSG #channel helloworld") + +class FormatTestSpacedArg(unittest.TestCase): + def test(self): + line = irctokens.format("USER", ["user", "0 *", "real name"]) + self.assertEqual(line, "USER user 0 * :real name")