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

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

[nongnu] elpa/bash-completion 6bf1536325 150/313: Fix occasional escapin


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 6bf1536325 150/313: Fix occasional escaping issue with candidates containing quotes.
Date: Sat, 3 Dec 2022 10:59:25 -0500 (EST)

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

    Fix occasional escaping issue with candidates containing quotes.
    
    bash-completion-escape-candidate used to attempt detect quoted
    strings. The idea was that programmable completion could return quoted
    strings. It's impossible, though, functions fill in results as bash
    strings in COMPRELPY; they don't print them.
    
    The commit f3b11e1 broke that idea by calling
    bash-completion-escape-candidate only on the substring that follows
    the stub to be completed. Since that change, single or double quotes
    anywhere in the strings could end up not being escaped when they
    should have been, just because they happened to be the first part of
    the string to append to the completion candidate.
    
    Example:
     cat Documents/Modes\ d<point>
    Now completes to:
     cat Documents/Modes\ d\'emplois<point>
    But would, before this commit, complete to:
      cat Documents/Modes\ d'emplois<point>
---
 bash-completion-test.el | 17 ++++++++++-------
 bash-completion.el      |  3 +--
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/bash-completion-test.el b/bash-completion-test.el
index 1fcd7cba49..cde751e50b 100644
--- a/bash-completion-test.el
+++ b/bash-completion-test.el
@@ -594,13 +594,16 @@ garbage
   (should (equal "hel\\lo, \\you"
                 (bash-completion-escape-candidate "hel\\lo, \\you" ?\")))
 
-  ;; no quote not if double quoted
-  (should (equal "\"hello, you"
-                (bash-completion-escape-candidate "\"hello, you" nil)))
-  
-  ;; no quote not if single quoted
-  (should (equal "'hello, you"
-                (bash-completion-escape-candidate "'hello, you" nil))))
+  ;; starts with quotes or special char
+  (should (equal "\\\"\\\"hello" (bash-completion-escape-candidate "\"\"hello" 
nil)))
+  (should (equal "\\'\\'hello" (bash-completion-escape-candidate "''hello" 
nil)))
+  (should (equal "\\#\\#hello" (bash-completion-escape-candidate "##hello" 
nil)))
+  (should (equal "\\\"\\\"hello" (bash-completion-escape-candidate "\"\"hello" 
?\")))
+  (should (equal "''hello" (bash-completion-escape-candidate "''hello" ?\")))
+  (should (equal "##hello" (bash-completion-escape-candidate "##hello" ?\")))
+  (should (equal "\"\"hello" (bash-completion-escape-candidate "\"\"hello" 
?')))
+  (should (equal "'\\'''\\''hello" (bash-completion-escape-candidate "''hello" 
?')))
+  (should (equal "##hello" (bash-completion-escape-candidate "##hello" ?'))))
 
 (ert-deftest bash-completion-quote-test ()
   ;; allowed
diff --git a/bash-completion.el b/bash-completion.el
index 89d953e631..ca15281907 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -856,8 +856,7 @@ OPEN-QUOTE, either nil, ' or \".
 Return a possibly escaped version of COMPLETION-CANDIDATE."
   (cond
    ((zerop (length completion-candidate)) "")
-   ((and (null open-quote)
-        (null (string-match "^['\"]" completion-candidate)))
+   ((null open-quote)
     (replace-regexp-in-string
      "\n" "'\n'"
      (replace-regexp-in-string



reply via email to

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