From 3f70567d5665e1300173a6a208fcf0fba3214181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Mon, 3 Jul 2017 23:31:14 +0200 Subject: [PATCH] Trim whitespace off IRC messages --- irc/conn_test.go | 2 +- irc/message.go | 2 +- irc/message_test.go | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/irc/conn_test.go b/irc/conn_test.go index 6f781b9c..5cea38a6 100644 --- a/irc/conn_test.go +++ b/irc/conn_test.go @@ -131,7 +131,7 @@ func TestRecv(t *testing.T) { buf.WriteString("001 foo\r\n") c.reader = bufio.NewReader(buf) - c.sendRecv.Add(2) + c.sendRecv.Add(1) go c.recv() assert.Equal(t, "PONG :test\r\n", <-conn.hook) diff --git a/irc/message.go b/irc/message.go index 32a320e3..be4cbfc3 100644 --- a/irc/message.go +++ b/irc/message.go @@ -19,7 +19,7 @@ func (m *Message) LastParam() string { } func parseMessage(line string) *Message { - line = strings.Trim(line, "\r\n") + line = strings.Trim(line, "\r\n ") msg := Message{} cmdStart := 0 cmdEnd := len(line) diff --git a/irc/message_test.go b/irc/message_test.go index da0a74b8..398431a9 100644 --- a/irc/message_test.go +++ b/irc/message_test.go @@ -64,6 +64,18 @@ func TestParseMessage(t *testing.T) { Nick: "ni@ck", Command: "CMD", }, + }, { + "CMD #cake pie \r\n", + &Message{ + Command: "CMD", + Params: []string{"#cake", "pie"}, + }, + }, { + " CMD #cake pie\r\n", + &Message{ + Command: "CMD", + Params: []string{"#cake", "pie"}, + }, }, }