From 1e48afeb8ff3be631155201c93ae6d909a9cebc2 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 12 Oct 2020 08:32:01 +1100 Subject: quote config file when editing --- pkg/commands/oscommands/os.go | 2 +- pkg/commands/oscommands/os_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 5d37e2f4f..6a40d519c 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -255,7 +255,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) { return nil, errors.New("No editor defined in $VISUAL, $EDITOR, or git config") } - splitCmd := str.ToArgv(fmt.Sprintf("%s %s", editor, filename)) + splitCmd := str.ToArgv(fmt.Sprintf("%s %s", editor, c.Quote(filename))) return c.PrepareSubProcess(splitCmd[0], splitCmd[1:]...), nil } diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index 78dfa48ec..e4859484c 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -227,6 +227,28 @@ func TestOSCommandEditFile(t *testing.T) { assert.NoError(t, err) }, }, + { + "file/with space", + func(name string, args ...string) *exec.Cmd { + if name == "which" { + return exec.Command("echo") + } + + assert.EqualValues(t, "vi", name) + assert.EqualValues(t, "file/with space", args[0]) + + return nil + }, + func(env string) string { + return "" + }, + func(cf string) (string, error) { + return "", nil + }, + func(cmd *exec.Cmd, err error) { + assert.NoError(t, err) + }, + }, } for _, s := range scenarios { -- cgit v1.2.3