mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 15:40:02 +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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -84,6 +85,10 @@ func ParseCommand(line string) (cmd editableCommand, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
spacesExpr = regexp.MustCompile(` +`)
|
||||||
|
)
|
||||||
|
|
||||||
func parseArg(line string) (arg string, rest string) {
|
func parseArg(line string) (arg string, rest string) {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
return
|
return
|
||||||
@ -92,7 +97,7 @@ func parseArg(line string) (arg string, rest string) {
|
|||||||
if strings.HasPrefix(line, ":") {
|
if strings.HasPrefix(line, ":") {
|
||||||
arg = line[1:]
|
arg = line[1:]
|
||||||
} else {
|
} else {
|
||||||
parts := strings.SplitN(line, " ", 2)
|
parts := spacesExpr.Split(line, 2)
|
||||||
arg = parts[0]
|
arg = parts[0]
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
rest = 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) {
|
func parseLine(line string) (command StringCode, args []string) {
|
||||||
args = make([]string, 0)
|
args = make([]string, 0)
|
||||||
for arg, rest := parseArg(line); arg != ""; arg, rest = parseArg(rest) {
|
for arg, rest := parseArg(line); arg != ""; arg, rest = parseArg(rest) {
|
||||||
|
if arg == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
args = append(args, arg)
|
args = append(args, arg)
|
||||||
}
|
}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user