summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorTommy Nguyen <remyabel@gmail.com>2018-08-15 23:55:55 -0400
committerTommy Nguyen <remyabel@gmail.com>2018-08-15 23:55:55 -0400
commitee4660af97a6da7fcb0a17474a9a6d70d0d7df0b (patch)
tree30a82c8f0425a2c482f88bbff53e0bb6fb500bc9 /pkg/commands
parent59ab38fff6bcfe8ec25c1cf658833cb8d0b69440 (diff)
#158: escapes backticks, which is a problem in shells like Bash
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/os.go3
-rw-r--r--pkg/commands/os_test.go16
2 files changed, 19 insertions, 0 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index 9f9819a5a..9ccdebc56 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"runtime"
+ "regexp"
"github.com/davecgh/go-spew/spew"
@@ -170,5 +171,7 @@ 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 {
+ r := regexp.MustCompile("`")
+ message = r.ReplaceAllString(message, "\\`")
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..a6bdbc1b1
--- /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)
+ }
+}