1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-26 09:00:57 +02:00

Merge pull request #159 from remyabel/158_escape_backticks

#158: escapes backticks, which is a problem in shells like Bash
This commit is contained in:
Jesse Duffield 2018-08-17 21:11:20 +10:00 committed by GitHub
commit aaa8558de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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
}

16
pkg/commands/os_test.go Normal file
View File

@ -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)
}
}