diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-17 21:11:20 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-17 21:11:20 +1000 |
commit | aaa8558de83b109e59e752819e02925da4c134b5 (patch) | |
tree | 7331a0094bd42522ef37ea1b43809139c4f050d3 | |
parent | 933aae7da12e0f5ee1ef8eada1e72e386cd68e51 (diff) | |
parent | 52033b32f702d1b0c0157b9dd9ecb77e8ddf82b0 (diff) |
Merge pull request #159 from remyabel/158_escape_backticks
#158: escapes backticks, which is a problem in shells like Bash
-rw-r--r-- | pkg/commands/os.go | 2 | ||||
-rw-r--r-- | pkg/commands/os_test.go | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go index d4ea75e74..f5efbac63 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "runtime" + "strings" "github.com/davecgh/go-spew/spew" @@ -163,5 +164,6 @@ func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) (*e // Quote wraps a message in platform-specific quotation marks func (c *OSCommand) Quote(message string) string { + message = strings.Replace(message, "`", "\\`", -1) return c.Platform.escapedQuote + message + c.Platform.escapedQuote } diff --git a/pkg/commands/os_test.go b/pkg/commands/os_test.go new file mode 100644 index 000000000..29540aff6 --- /dev/null +++ b/pkg/commands/os_test.go @@ -0,0 +1,16 @@ +package commands + +import "testing" + +func TestQuote(t *testing.T) { + osCommand := &OSCommand{ + Log: nil, + Platform: getPlatform(), + } + test := "hello `test`" + expected := osCommand.Platform.escapedQuote + "hello \\`test\\`" + osCommand.Platform.escapedQuote + test = osCommand.Quote(test) + if test != expected { + t.Error("Expected " + expected + ", got " + test) + } +} |