mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-28 04:14:56 +03:00
#158: escapes backticks, which is a problem in shells like Bash
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"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
|
// Quote wraps a message in platform-specific quotation marks
|
||||||
func (c *OSCommand) Quote(message string) string {
|
func (c *OSCommand) Quote(message string) string {
|
||||||
|
r := regexp.MustCompile("`")
|
||||||
|
message = r.ReplaceAllString(message, "\\`")
|
||||||
return c.Platform.escapedQuote + message + c.Platform.escapedQuote
|
return c.Platform.escapedQuote + message + c.Platform.escapedQuote
|
||||||
}
|
}
|
||||||
|
|||||||
16
pkg/commands/os_test.go
Normal file
16
pkg/commands/os_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user