emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 c8ea14e7825: Handle quoted tilde in Tramp


From: Michael Albinus
Subject: emacs-29 c8ea14e7825: Handle quoted tilde in Tramp
Date: Fri, 13 Oct 2023 10:10:06 -0400 (EDT)

branch: emacs-29
commit c8ea14e7825d536f41a230fc1298341a2462635e
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Handle quoted tilde in Tramp
    
    * lisp/net/tramp.el (tramp-handle-expand-file-name):
    * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-expand-file-name):
    * lisp/net/tramp-sh.el (tramp-sh-handle-expand-file-name):
    * lisp/net/tramp-smb.el (tramp-smb-handle-expand-file-name):
    * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-expand-file-name):
    Handle quoted tilde.  (Bug#65685)
    
    * test/lisp/net/tramp-tests.el (tramp-test05-expand-file-name-tilde):
    New test.
---
 lisp/net/tramp-gvfs.el       |  5 ++++-
 lisp/net/tramp-sh.el         |  3 +++
 lisp/net/tramp-smb.el        |  3 +++
 lisp/net/tramp-sudoedit.el   |  3 +++
 lisp/net/tramp.el            |  3 +++
 test/lisp/net/tramp-tests.el | 11 +++++++++++
 6 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 46342042880..07390b50df2 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -1176,10 +1176,13 @@ file names."
       (tramp-run-real-handler #'expand-file-name (list name))
     ;; Dissect NAME.
     (with-parsed-tramp-file-name name nil
+      ;; Tilde expansion shall be possible also for quoted localname.
+      (when (string-prefix-p "~" (file-name-unquote localname))
+       (setq localname (file-name-unquote localname)))
       ;; If there is a default location, expand tilde.
       (when (string-match
             (tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) 
eos)
-             localname)
+            localname)
        (let ((uname (match-string 1 localname))
              (fname (match-string 2 localname))
              hname)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 59d5c00515f..74b1638f120 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -2831,6 +2831,9 @@ the result will be a local, non-Tramp, file name."
           (tramp-run-real-handler #'expand-file-name (list name)))
        (unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
          (setq localname (concat "~/" localname)))
+        ;; Tilde expansion shall be possible also for quoted localname.
+       (when (string-prefix-p "~" (file-name-unquote localname))
+         (setq localname (file-name-unquote localname)))
        ;; Tilde expansion if necessary.  This needs a shell which
        ;; groks tilde expansion!  The function `tramp-find-shell' is
        ;; supposed to find such a shell on the remote host.  Please
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 7249fa266ac..0ba24352a3d 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -731,6 +731,9 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are 
completely ignored."
       (tramp-run-real-handler #'expand-file-name (list name))
     ;; Dissect NAME.
     (with-parsed-tramp-file-name name nil
+      ;; Tilde expansion shall be possible also for quoted localname.
+      (when (string-prefix-p "~" (file-name-unquote localname))
+       (setq localname (file-name-unquote localname)))
       ;; Tilde expansion if necessary.
       (when (string-match
             (tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) 
eos)
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index d167bf13b14..9939d93ba35 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -380,6 +380,9 @@ the result will be a local, non-Tramp, file name."
       ;; but to the root home directory.
       (when (tramp-string-empty-or-nil-p localname)
        (setq localname "~"))
+      ;; Tilde expansion shall be possible also for quoted localname.
+      (when (string-prefix-p "~" (file-name-unquote localname))
+       (setq localname (file-name-unquote localname)))
       (unless (file-name-absolute-p localname)
        (setq localname (format "~%s/%s" user localname)))
       (when (string-match
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 02051736cc5..d1b38cfeb93 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3982,6 +3982,9 @@ Let-bind it when necessary.")
     (with-parsed-tramp-file-name name nil
       (unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
        (setq localname (concat "/" localname)))
+      ;; Tilde expansion shall be possible also for quoted localname.
+      (when (string-prefix-p "~" (file-name-unquote localname))
+       (setq localname (file-name-unquote localname)))
       ;; Expand tilde.  Usually, the methods applying this handler do
       ;; not support tilde expansion.  But users could declare a
       ;; respective connection property.  (Bug#53847)
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 0648fe9e80f..e74837b926a 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -2335,6 +2335,17 @@ Also see `ignore'."
       (should (string-equal (expand-file-name local dir) dir))
       (should (string-equal (expand-file-name (concat dir local)) dir)))))
 
+;; The following test is inspired by Bug#65685.
+(ert-deftest tramp-test05-expand-file-name-tilde ()
+  "Check `expand-file-name'."
+  (skip-unless (tramp--test-enabled))
+  (skip-unless (not (tramp--test-ange-ftp-p)))
+
+  (let ((dir (file-remote-p ert-remote-temporary-file-directory))
+       (tramp-tolerate-tilde t))
+    (should (string-equal (expand-file-name (concat dir "~"))
+                         (expand-file-name (concat dir "/:~"))))))
+
 (ert-deftest tramp-test06-directory-file-name ()
   "Check `directory-file-name'.
 This checks also `file-name-as-directory', `file-name-directory',



reply via email to

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