From a51be5037d3f32ad09e04bb6c2d0eb745d2fadaa Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 6 Sep 2021 10:52:06 +0200 Subject: [PATCH] lib/irc: only add colon to trailing arg when necessary This mirrors go-irc's behavior: https://github.com/go-irc/irc/blob/7ba1a1858f5ee2a44f18501b486ec11dd1990018/parser.go#L374 Closes: https://todo.sr.ht/~emersion/gamja/103 --- lib/irc.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/irc.js b/lib/irc.js index 5024e7d..5ee4a9c 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -215,11 +215,14 @@ export function formatMessage(msg) { } s += msg.command; if (msg.params && msg.params.length > 0) { - let last = msg.params[msg.params.length - 1]; - if (msg.params.length > 1) { - s += " " + msg.params.slice(0, -1).join(" "); + s += " " + msg.params.slice(0, -1).join(" "); + + let last = String(msg.params[msg.params.length - 1]); + if (last.length === 0 || last === ":" || last.indexOf(" ") >= 0) { + s += " :" + last; + } else { + s += " " + last; } - s += " :" + last; } s += "\r\n"; return s;