aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-02-10 14:19:07 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-02-10 14:19:07 +0100
commit7ed9825ea766672ba6fa05987b868cb3ab131185 (patch)
treef67cdcaabc501632f1466e6ad7c29abc0b3e6f86
parent94d20330c4b92e2098db2e40fee62ad8b2feead1 (diff)
downloadgoffel-7ed9825ea766672ba6fa05987b868cb3ab131185.tar.gz
goffel-7ed9825ea766672ba6fa05987b868cb3ab131185.zip
cmd: trim whitespace before processing input
-rw-r--r--logic/cmd.go1
-rw-r--r--logic/cmd_test.go8
2 files changed, 9 insertions, 0 deletions
diff --git a/logic/cmd.go b/logic/cmd.go
index 33cd705..078da36 100644
--- a/logic/cmd.go
+++ b/logic/cmd.go
@@ -29,6 +29,7 @@ var cmdTable = map[string]int{
// we ignore arguments which are to much
func ParseCmd(s string) (Cmd, error) {
+ s = strings.Trim(s, " \t")
split := strings.Split(s, " ")
if len(split) == 0 {
return Cmd{}, errors.New("Empty command")
diff --git a/logic/cmd_test.go b/logic/cmd_test.go
index d7c88ba..78e9b41 100644
--- a/logic/cmd_test.go
+++ b/logic/cmd_test.go
@@ -11,6 +11,14 @@ func TestParseCmd(t *testing.T) {
t.Errorf("Parsing an empty string should return an error")
}
+ cmd, err = ParseCmd(" q \t ")
+ if err != nil {
+ t.Errorf("Parsing \" q \\t \" should not return \"%v\"", err)
+ }
+ if cmd.Cmd != "q" {
+ t.Errorf("Parsing \" q \\t \" should return \"q\" as command")
+ }
+
for _, s := range []string{"d", "p", "h"} {
cmd, err = ParseCmd(s)
if err != nil {