From 6a465500bc3844259013ba62e0686dc030dcf1ea Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 6 Jan 2020 11:38:21 -0500 Subject: [PATCH] Properly handle empty args with new shellquote lib Fixes #1454 --- internal/action/actions.go | 6 +++++- internal/action/command.go | 7 +++++++ internal/action/terminal_supported.go | 3 +++ internal/shell/shell.go | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index a85f7bbb..b48cf82a 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -667,11 +667,15 @@ func (h *BufPane) SaveAs() bool { if !canceled { // the filename might or might not be quoted, so unquote first then join the strings. args, err := shellquote.Split(resp) - filename := strings.Join(args, " ") if err != nil { InfoBar.Error("Error parsing arguments: ", err) return } + if len(args) == 0 { + InfoBar.Error("No filename given") + return + } + filename := strings.Join(args, " ") noPrompt := h.saveBufToFile(filename, "SaveAs") if noPrompt { h.completeAction("SaveAs") diff --git a/internal/action/command.go b/internal/action/command.go index 1d88d8cc..4960ae9e 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -349,6 +349,9 @@ func (h *BufPane) OpenCmd(args []string) { InfoBar.Error("Error parsing args ", err) return } + if len(args) == 0 { + return + } filename = strings.Join(args, " ") open := func() { @@ -966,6 +969,10 @@ func (h *BufPane) HandleCommand(input string) { return } + if len(args) == 0 { + return + } + inputCmd := args[0] if _, ok := commands[inputCmd]; !ok { diff --git a/internal/action/terminal_supported.go b/internal/action/terminal_supported.go index b0b10632..3ae19ff1 100644 --- a/internal/action/terminal_supported.go +++ b/internal/action/terminal_supported.go @@ -14,6 +14,9 @@ func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callba if err != nil { return err } + if len(args) == 0 { + return nil + } t := new(shell.Terminal) t.Start(args, getOutput, wait, callback, userargs) diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 24df587f..53bf67ce 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -2,6 +2,7 @@ package shell import ( "bytes" + "errors" "fmt" "io" "os" @@ -36,6 +37,9 @@ func RunCommand(input string) (string, error) { if err != nil { return "", err } + if len(args) == 0 { + return "", errors.New("No arguments") + } inputCmd := args[0] return ExecCommand(inputCmd, args[1:]...) @@ -49,6 +53,9 @@ func RunBackgroundShell(input string) (func() string, error) { if err != nil { return nil, err } + if len(args) == 0 { + return nil, errors.New("No arguments") + } inputCmd := args[0] return func() string { output, err := RunCommand(input) @@ -72,6 +79,9 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error if err != nil { return "", err } + if len(args) == 0 { + return "", errors.New("No arguments") + } inputCmd := args[0] // Shut down the screen because we're going to interact directly with the shell