mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
be more lax about whitespace when parsing commands from clients
This commit is contained in:
parent
c1edddb9a1
commit
f9bf422ba7
@ -3,6 +3,7 @@ package irc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -84,6 +85,10 @@ func ParseCommand(line string) (cmd editableCommand, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
spacesExpr = regexp.MustCompile(` +`)
|
||||
)
|
||||
|
||||
func parseArg(line string) (arg string, rest string) {
|
||||
if line == "" {
|
||||
return
|
||||
@ -92,7 +97,7 @@ func parseArg(line string) (arg string, rest string) {
|
||||
if strings.HasPrefix(line, ":") {
|
||||
arg = line[1:]
|
||||
} else {
|
||||
parts := strings.SplitN(line, " ", 2)
|
||||
parts := spacesExpr.Split(line, 2)
|
||||
arg = parts[0]
|
||||
if len(parts) > 1 {
|
||||
rest = parts[1]
|
||||
@ -104,6 +109,9 @@ func parseArg(line string) (arg string, rest string) {
|
||||
func parseLine(line string) (command StringCode, args []string) {
|
||||
args = make([]string, 0)
|
||||
for arg, rest := parseArg(line); arg != ""; arg, rest = parseArg(rest) {
|
||||
if arg == "" {
|
||||
continue
|
||||
}
|
||||
args = append(args, arg)
|
||||
}
|
||||
if len(args) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user