lib/irc: only add colon to trailing arg when necessary

This mirrors go-irc's behavior:

7ba1a1858f/parser.go (L374)

Closes: https://todo.sr.ht/~emersion/gamja/103
This commit is contained in:
Simon Ser 2021-09-06 10:52:06 +02:00
parent c428e504fe
commit a51be5037d

View file

@ -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(" ");
}
let last = String(msg.params[msg.params.length - 1]);
if (last.length === 0 || last === ":" || last.indexOf(" ") >= 0) {
s += " :" + last;
} else {
s += " " + last;
}
}
s += "\r\n";
return s;