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.
This commit is contained in:
Michael Albinus 2023-10-13 16:09:51 +02:00
parent 30239759ee
commit c8ea14e782
6 changed files with 27 additions and 1 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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',