ircmsg: Improve robustness

This commit is contained in:
Daniel Oaks 2016-11-04 21:20:04 +10:00
parent 649590699f
commit 63f6c66ea1

@ -63,6 +63,10 @@ func ParseLine(line string) (IrcMessage, error) {
}
}
if len(line) < 1 {
return ircmsg, ErrorLineIsEmpty
}
// prefix
if line[0] == ':' {
splitLine := strings.SplitN(line, " ", 2)
@ -70,6 +74,10 @@ func ParseLine(line string) (IrcMessage, error) {
line = strings.TrimLeft(splitLine[1], " ")
}
if len(line) < 1 {
return ircmsg, ErrorLineIsEmpty
}
// command
splitLine := strings.SplitN(line, " ", 2)
ircmsg.Command = strings.ToUpper(splitLine[0])