diff --git a/irc/message.go b/irc/message.go index 6e0ad59f..dfec47de 100644 --- a/irc/message.go +++ b/irc/message.go @@ -19,7 +19,13 @@ func parseMessage(line string) *Message { if strings.HasPrefix(line, ":") { cmdStart = strings.Index(line, " ") + 1 - msg.Prefix = line[1 : cmdStart-1] + + if cmdStart > 0 { + msg.Prefix = line[1 : cmdStart-1] + } else { + // Invalid message + return &msg + } if i := strings.Index(msg.Prefix, "!"); i > 0 { msg.Nick = msg.Prefix[:i] diff --git a/irc/message_test.go b/irc/message_test.go index 2d66228a..9ea7b94f 100644 --- a/irc/message_test.go +++ b/irc/message_test.go @@ -71,3 +71,10 @@ func TestParseMessage(t *testing.T) { assert.Equal(t, tc.expected, parseMessage(tc.input)) } } + +func TestBadMessagePanic(t *testing.T) { + parseMessage(":user\r\n") + parseMessage(":\r\n") + parseMessage(":") + parseMessage("") +}