diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-04-30 23:18:50 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-04-30 23:18:50 +0200 |
commit | d93e21243d3805db56ec42004f12285125d28aef (patch) | |
tree | bee0ba8bcddb9c4a418062dbb30b50eb4cedf643 | |
parent | 442ec506536627d73254c5df03144175c22de1c0 (diff) |
Escape quotes in paths
-rw-r--r-- | queue/queue.go | 14 | ||||
-rw-r--r-- | queue/queue_test.go | 2 |
2 files changed, 14 insertions, 2 deletions
diff --git a/queue/queue.go b/queue/queue.go index 1c309bb..daa3b71 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -112,6 +112,16 @@ func (q *Queue) PostProcess(inheritIO bool) error { func (q Queue) MarshalText() ([]byte, error) { var buf bytes.Buffer + escapeQuotes := func(s string) { + var prev rune + for _, c := range s { + if c == '\'' && prev != '\\' { + buf.WriteRune('\\') + } + buf.WriteRune(c) + prev = c + } + } buf.WriteString("open ") buf.WriteString(q.Site.Name) buf.WriteString("\n") @@ -119,9 +129,9 @@ func (q Queue) MarshalText() ([]byte, error) { buf.WriteString("queue ") buf.WriteString(q.Site.GetCmd) buf.WriteString(" '") - buf.WriteString(item.RemotePath) + escapeQuotes(item.RemotePath) buf.WriteString("' '") - buf.WriteString(item.LocalPath) + escapeQuotes(item.LocalPath) buf.WriteString("'\n") } buf.WriteString("queue start\nwait\n") diff --git a/queue/queue_test.go b/queue/queue_test.go index cc3cb9d..e40222d 100644 --- a/queue/queue_test.go +++ b/queue/queue_test.go @@ -363,6 +363,7 @@ func TestMarshalText(t *testing.T) { items := []Item{ {RemotePath: "/remote/foo", LocalPath: "/local", Transfer: true}, {RemotePath: "/remote/bar", LocalPath: "/local", Transfer: true}, + {RemotePath: "/remote/bar with ' and \\'", LocalPath: "/local with ' and \\'", Transfer: true}, } var q encoding.TextMarshaler = Queue{Site: s, Items: items} out, err := q.MarshalText() @@ -372,6 +373,7 @@ func TestMarshalText(t *testing.T) { expected := `open siteA queue mirror '/remote/foo' '/local' queue mirror '/remote/bar' '/local' +queue mirror '/remote/bar with \' and \'' '/local with \' and \'' queue start wait ` |