From c14a7aae52744805c7d7f58e6a25889ce2f4478d Mon Sep 17 00:00:00 2001 From: Zlepper Date: Wed, 16 Aug 2017 14:41:03 +0200 Subject: [PATCH] Fix windows paths being escaped incorrectly --- process-manager.go | 11 ++++++++--- process-manager_test.go | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/process-manager.go b/process-manager.go index 7dbd091..2ebf401 100644 --- a/process-manager.go +++ b/process-manager.go @@ -47,7 +47,7 @@ func Tokenize(s string) (tokens []string) { hasQuote := false // True if the next char should be treated as a literal escapeNext := false - for _, char := range s { + for index, char := range s { if escapeNext { token += string(char) escapeNext = false @@ -65,8 +65,13 @@ func Tokenize(s string) (tokens []string) { } if char == '\\' { - escapeNext = true - continue + if index+1 < len(s) { + nextChar := s[index+1] + if nextChar == ' ' || nextChar == '"' { + escapeNext = true + continue + } + } } if char == ' ' { diff --git a/process-manager_test.go b/process-manager_test.go index 5759c91..64deb41 100644 --- a/process-manager_test.go +++ b/process-manager_test.go @@ -6,8 +6,8 @@ import ( ) func TestTokenize(t *testing.T) { - s := `gfs --config=/foo/var --serve=\"/bar\ baz/foo\" -d /var\ foo "var foo"` - expected := []string{`gfs`, `--config=/foo/var`, `--serve="/bar baz/foo"`, "-d", "/var foo", "var foo"} + s := `gfs --config=/foo/var --serve=\"/bar\ baz/foo\" -d /var\ foo "var foo" C:\this\is\test` + expected := []string{`gfs`, `--config=/foo/var`, `--serve="/bar baz/foo"`, "-d", "/var foo", "var foo", `C:\this\is\test`} actual := Tokenize(s)