Properly handle empty args with new shellquote lib

Fixes #1454
This commit is contained in:
Zachary Yedidia
2020-01-06 11:38:21 -05:00
parent f3e8413e77
commit 6a465500bc
4 changed files with 25 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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