]> git.lizzy.rs Git - micro.git/commitdiff
Properly handle empty args with new shellquote lib
authorZachary Yedidia <zyedidia@gmail.com>
Mon, 6 Jan 2020 16:38:21 +0000 (11:38 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Mon, 6 Jan 2020 16:38:21 +0000 (11:38 -0500)
Fixes #1454

internal/action/actions.go
internal/action/command.go
internal/action/terminal_supported.go
internal/shell/shell.go

index a85f7bbb8c2213c70a1e1e2da651c1c3cd2526b9..b48cf82af505f6866a404130a6e65e452aa53c16 100644 (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")
index 1d88d8cc60cbb6421cb1f0402af354b9ec924a51..4960ae9e960d3674938de62c40a784dfee1931b0 100644 (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 {
index b0b10632b3d8773be3efa56541fbc65b8aff67a6..3ae19ff1e0de51cf2538b2d0ffba24d7f9817a36 100644 (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)
index 24df587f1c129d22cc0ca4c8ea04a0ce259a420d..53bf67ce4215616b9ef3ba188baf84fe1d9de5d9 100644 (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