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
This commit is contained in:
Simon Ser
2021-09-06 10:52:06 +02:00
parent c428e504fe
commit a51be5037d
+7 -4
View File
@@ -215,11 +215,14 @@ export function formatMessage(msg) {
} }
s += msg.command; s += msg.command;
if (msg.params && msg.params.length > 0) { if (msg.params && msg.params.length > 0) {
let last = msg.params[msg.params.length - 1]; s += " " + msg.params.slice(0, -1).join(" ");
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 += " :" + last;
} }
s += "\r\n"; s += "\r\n";
return s; return s;