trim to newline bytes more aggressively
This commit is contained in:
parent
75aee58953
commit
d3f23f4ea7
@ -147,14 +147,6 @@ func ParseLineStrict(line string, fromClient bool, truncateLen int) (ircmsg IrcM
|
||||
return parseLine(line, maxTagDataLength, truncateLen)
|
||||
}
|
||||
|
||||
// slice off any amount of '\r' or '\n' from the end of the string
|
||||
func trimFinalNewlines(str string) string {
|
||||
var i int
|
||||
for i = len(str) - 1; 0 <= i && (str[i] == '\r' || str[i] == '\n'); i -= 1 {
|
||||
}
|
||||
return str[:i+1]
|
||||
}
|
||||
|
||||
// slice off any amount of ' ' from the front of the string
|
||||
func trimInitialSpaces(str string) string {
|
||||
var i int
|
||||
@ -169,7 +161,15 @@ func parseLine(line string, maxTagDataLength int, truncateLen int) (ircmsg IrcMe
|
||||
return
|
||||
}
|
||||
|
||||
line = trimFinalNewlines(line)
|
||||
// trim to the first appearance of either '\r' or '\n':
|
||||
lineEnd := strings.IndexByte(line, '\r')
|
||||
newlineIndex := strings.IndexByte(line, '\n')
|
||||
if newlineIndex != -1 && (lineEnd == -1 || newlineIndex < lineEnd) {
|
||||
lineEnd = newlineIndex
|
||||
}
|
||||
if lineEnd != -1 {
|
||||
line = line[:lineEnd]
|
||||
}
|
||||
|
||||
if len(line) < 1 {
|
||||
return ircmsg, ErrorLineIsEmpty
|
||||
@ -223,7 +223,7 @@ func parseLine(line string, maxTagDataLength int, truncateLen int) (ircmsg IrcMe
|
||||
paramStart = len(line)
|
||||
}
|
||||
// normalize command to uppercase:
|
||||
ircmsg.Command = strings.ToUpper(strings.TrimSpace(line[:commandEnd]))
|
||||
ircmsg.Command = strings.ToUpper(line[:commandEnd])
|
||||
if len(ircmsg.Command) == 0 {
|
||||
return ircmsg, ErrorLineIsEmpty
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user