Skip to content

Commit

Permalink
Fix windows paths being escaped incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
zlepper committed Aug 16, 2017
1 parent b8ef9a4 commit c14a7aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions process-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 == ' ' {
Expand Down
4 changes: 2 additions & 2 deletions process-manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c14a7aa

Please sign in to comment.