]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/files.el (file-name-non-special): Handle quoted tilde.
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 14 Oct 2023 07:34:40 +0000 (09:34 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 14 Oct 2023 07:34:40 +0000 (09:34 +0200)
(Bug#65685)

* test/lisp/files-tests.el
(files-tests-file-name-non-special-expand-file-name-tilde):
New test.

lisp/files.el
test/lisp/files-tests.el

index b72f141c0eec490dcfdc1a21920b34497d561c24..8b5cb4964cc27c0ef6015dc00329cd40d50a03ed 100644 (file)
@@ -8185,13 +8185,12 @@ arguments as the running Emacs)."
        ;; Get a list of the indices of the args that are file names.
        (file-arg-indices
         (cdr (or (assq operation
-                       '(;; The first eight are special because they
+                       '(;; The first seven are special because they
                          ;; return a file name.  We want to include
                          ;; the /: in the return value.  So just
                          ;; avoid stripping it in the first place.
                           (abbreviate-file-name)
                           (directory-file-name)
-                          (expand-file-name)
                           (file-name-as-directory)
                           (file-name-directory)
                           (file-name-sans-versions)
@@ -8200,6 +8199,10 @@ arguments as the running Emacs)."
                          ;; `identity' means just return the first
                          ;; arg not stripped of its quoting.
                          (substitute-in-file-name identity)
+                          ;; `expand-file-name' shall do special case
+                          ;; for the first argument starting with
+                          ;; "/:~".  (Bug#65685)
+                          (expand-file-name expand-file-name)
                          ;; `add' means add "/:" to the result.
                          (file-truename add 0)
                           ;;`insert-file-contents' needs special handling.
@@ -8255,6 +8258,10 @@ arguments as the running Emacs)."
     (let ((tramp-mode (and tramp-mode (eq method 'local-copy))))
       (pcase method
         ('identity (car arguments))
+        ('expand-file-name
+         (when (string-prefix-p "/:~" (car arguments))
+           (setcar arguments (file-name-unquote (car arguments) t)))
+         (apply operation arguments))
         ('add (file-name-quote (apply operation arguments) t))
         ('buffer-file-name
          (let ((buffer-file-name (file-name-unquote buffer-file-name t)))
index aadb60e1de7e468c7a0b8e0b11fc034e66d44759..8f6495a293c629ef01eee55ff249949861caec81 100644 (file)
@@ -662,6 +662,23 @@ unquoted file names."
   (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
     (should (equal (expand-file-name nospecial) nospecial))))
 
+(ert-deftest files-tests-file-name-non-special-expand-file-name-tilde ()
+  (let ((process-environment
+         (cons (format "HOME=%s" temporary-file-directory) process-environment))
+        abbreviated-home-dir)
+    (files-tests--with-temp-non-special (tmpfile nospecial)
+      (let (file-name-handler-alist)
+        (setq nospecial (file-name-quote (abbreviate-file-name tmpfile))))
+      (should (equal (expand-file-name nospecial)
+                     (expand-file-name (file-name-unquote nospecial t)))))
+    (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
+      (let (file-name-handler-alist)
+        (setq nospecial (file-name-quote (abbreviate-file-name tmpfile))))
+      (should-not
+       (equal (expand-file-name nospecial)
+              ;; The file name handler deletes the ".special" extension.
+              (expand-file-name (file-name-unquote nospecial t)))))))
+
 (ert-deftest files-tests-file-name-non-special-file-accessible-directory-p ()
   (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
     (should (file-accessible-directory-p nospecial-dir)))