diff --git a/irc/message.go b/irc/message.go index be4cbfc3..c2050c47 100644 --- a/irc/message.go +++ b/irc/message.go @@ -49,11 +49,11 @@ func parseMessage(line string) *Message { trailing = line[i+2:] } - cmd := strings.Split(line[cmdStart:cmdEnd], " ") - msg.Command = cmd[0] - if msg.Command == "" { + cmd := strings.Fields(line[cmdStart:cmdEnd]) + if len(cmd) == 0 { return nil } + msg.Command = cmd[0] if len(cmd) > 1 { msg.Params = cmd[1:] diff --git a/irc/message_test.go b/irc/message_test.go index 398431a9..1a172013 100644 --- a/irc/message_test.go +++ b/irc/message_test.go @@ -76,6 +76,30 @@ func TestParseMessage(t *testing.T) { Command: "CMD", Params: []string{"#cake", "pie"}, }, + }, { + "CMD #cake ::pie\r\n", + &Message{ + Command: "CMD", + Params: []string{"#cake", ":pie"}, + }, + }, { + "CMD #cake : pie\r\n", + &Message{ + Command: "CMD", + Params: []string{"#cake", " pie"}, + }, + }, { + "CMD #cake :pie :P <3\r\n", + &Message{ + Command: "CMD", + Params: []string{"#cake", "pie :P <3"}, + }, + }, { + "CMD #cake :pie!\r\n", + &Message{ + Command: "CMD", + Params: []string{"#cake", "pie!"}, + }, }, }