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

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

[nongnu] elpa/bash-completion 8ca917f428 133/313: Stop escaping = in com


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 8ca917f428 133/313: Stop escaping = in completion. fixes #18
Date: Sat, 3 Dec 2022 10:59:24 -0500 (EST)

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

    Stop escaping = in completion. fixes #18
    
    Previously, bash-completion.el used shell-quote-argument from subr.el to
    quote unsafe characters, which has a rather restrictive view of which
    characters can be considered safe. This commit replaces
    shell-quote-argument with custom code, and introduces
    bash-completion-special-chars. This is, for now, the same regexp as in
    shell-quote-argument, with = whitelisted.
    
    Moving away from shell-quote-argument also avoids possible issues with
    quoting on windows: since we know we're communicating with bash, there's
    no reason to quote characters in a way that's platform-specific.
---
 bash-completion-test.el | 4 ++++
 bash-completion.el      | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/bash-completion-test.el b/bash-completion-test.el
index b400fd36d7..ac2241535b 100644
--- a/bash-completion-test.el
+++ b/bash-completion-test.el
@@ -547,6 +547,10 @@ garbage
   (should (equal "\\(hello\\)"
                 (bash-completion-escape-candidate "(hello)" nil)))
 
+  ;; no quote
+  (should (equal "--hello="
+                (bash-completion-escape-candidate "--hello=" nil)))
+
   ;; single quote
   (should (equal "He said: \"hello, '\\''you'\\''\""
                 (bash-completion-escape-candidate "He said: \"hello, 'you'\"" 
?')))
diff --git a/bash-completion.el b/bash-completion.el
index 43931dc19d..8a6baac957 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -224,6 +224,9 @@ completion in colon-separated values.")
   (append bash-completion-wordbreaks-str nil)
   "`bash-completion-wordbreaks-str' as a list of characters.")
 
+(defconst bash-completion-special-chars "[^-0-9a-zA-Z_./\n=]"
+  "Regexp of characters that must be escaped or quoted.")
+
 (defconst bash-completion-wrapped-status
   "\e\ebash-completion-wrapped-status=124\e\e"
   "String output by __bash_complete_wrapper when the wrapped
@@ -760,7 +763,10 @@ Return a possibly escaped version of COMPLETION-CANDIDATE."
    ((zerop (length completion-candidate)) "")
    ((and (null open-quote)
         (null (string-match "^['\"]" completion-candidate)))
-    (shell-quote-argument completion-candidate))
+    (replace-regexp-in-string
+     "\n" "'\n'"
+     (replace-regexp-in-string
+      bash-completion-special-chars "\\\\\\&" completion-candidate)))
    ((eq ?' open-quote)
     (replace-regexp-in-string "'" "'\\''" completion-candidate nil t))
    ((eq ?\" open-quote)



reply via email to

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