emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/bash-completion 6ab1fe406b 148/313: Always quote the stub


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 6ab1fe406b 148/313: Always quote the stub before passing it to compgen.
Date: Sat, 3 Dec 2022 10:59:25 -0500 (EST)

branch: elpa/bash-completion
commit 6ab1fe406b774ef3cc9defb7b79c421ee9027ab7
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>

    Always quote the stub before passing it to compgen.
    
    Before this commit, the stub was quoted only sometimes, when doing
    custom completion using a function. This caused issues when completing
    stubs with spaces.
---
 bash-completion-test.el | 18 +++++++++++++++++-
 bash-completion.el      | 11 ++++++-----
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/bash-completion-test.el b/bash-completion-test.el
index f9a5b2ee1f..4c4902c457 100644
--- a/bash-completion-test.el
+++ b/bash-completion-test.el
@@ -814,7 +814,12 @@ before calling `bash-completion-dynamic-complete-nocomint'.
    (should (equal
             '("Documents/Modes\\ d\\'emplois/KAR\\ 1.pdf"
               "Documents/Modes\\ d\\'emplois/KAR\\ 2.pdf")
-            (nth 2(bash-completion-dynamic-complete-nocomint 3 (point)))))))
+            (nth 2(bash-completion-dynamic-complete-nocomint 3 (point)))))
+   (should (equal
+            (concat
+             "cd >/dev/null 2>&1 /tmp/test ; "
+             "compgen -o default -- 'Documents/Modes d'\\''emplois/' 
2>/dev/null")
+            (pop --captured-commands)))))
 
 (ert-deftest bash-completion-complete-single-quoted-dir ()
   (--with-fake-bash-completion-send
@@ -851,6 +856,17 @@ before calling `bash-completion-dynamic-complete-nocomint'.
                           "compgen -b -c -a -A function -- b 2>/dev/null")
                   (pop --captured-commands)))))
 
+(ert-deftest bash-completion-complete-command-with-space ()
+  (--with-fake-bash-completion-send
+   (push "some command\n" --send-results)
+   (insert "$ some\\ c")
+   (should (equal
+            '("some\\ command ")
+            (nth 2 (bash-completion-dynamic-complete-nocomint 3 (point)))))
+   (should (equal (concat "cd >/dev/null 2>&1 /tmp/test ; "
+                          "compgen -b -c -a -A function -- 'some c' 
2>/dev/null")
+                  (pop --captured-commands)))))
+
 (ert-deftest bash-completion-failed-completion ()
   (--with-fake-bash-completion-send
    (setq --send-results '("" "bad"))
diff --git a/bash-completion.el b/bash-completion.el
index 0c44a8121b..141dfdc22e 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -1101,19 +1101,19 @@ completion candidates."
           (compgen-args
            (or (cdr (assoc command-name bash-completion-alist))
                (and allowdefault (cdr (assoc nil bash-completion-alist)))))
-          (stub (nth cword words))
+          (quoted-stub (bash-completion-quote (nth cword words)))
           (completion-type)
           (commandline) )
     (cond
       ((= cword 0)
        ;; a command. let bash expand builtins, aliases and functions
        (setq completion-type 'command)
-       (setq commandline (concat "compgen -b -c -a -A function -- " stub)))
+       (setq commandline (concat "compgen -b -c -a -A function -- " 
quoted-stub)))
 
       ((not compgen-args)
        ;; no completion configured for this command
        (setq completion-type 'default)
-       (setq commandline (concat "compgen -o default -- " stub)))
+       (setq commandline (concat "compgen -o default -- " quoted-stub)))
 
       ((or (member "-F" compgen-args) (member "-C" compgen-args))
        ;; custom completion with a function of command
@@ -1133,11 +1133,12 @@ completion candidates."
                          (bash-completion-join words)
                          (bash-completion-quote function-name)))
                 (bash-completion-join args)
-                (bash-completion-quote stub)))))
+                quoted-stub))))
       (t
        ;; simple custom completion
        (setq completion-type 'custom)
-       (setq commandline (format "compgen %s -- %s" (bash-completion-join 
compgen-args) stub))))
+       (setq commandline (format "compgen %s -- %s" (bash-completion-join 
compgen-args)
+                                 quoted-stub))))
     (cons completion-type
           (concat
            (bash-completion-cd-command-prefix)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]