]> git.eshelyaron.com Git - emacs.git/commitdiff
In Eshell, don't expand quoted tildes into a user's home directory
authorJim Porter <jporterbugs@gmail.com>
Sun, 3 Sep 2023 05:29:22 +0000 (22:29 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 31 Jan 2024 20:15:24 +0000 (21:15 +0100)
* lisp/eshell/em-dirs.el (eshell-parse-user-reference): Don't expand
quoted tildes.

* test/lisp/eshell/em-dirs-tests.el
(em-dirs-test/expand-user-reference/local)
(em-dirs-test/expand-user-reference/quoted): New tests.

(cherry picked from commit d2abe91d4bf68f20e4b1cd39f88ed98fd5731524)

lisp/eshell/em-dirs.el
test/lisp/eshell/em-dirs-tests.el

index 85036620c5714f8f2e6fdee3becd63e6dde37a42..07063afc28638e56dcba82c9c2230df7210a1b12 100644 (file)
@@ -262,6 +262,7 @@ Thus, this does not include the current directory.")
 (defun eshell-parse-user-reference ()
   "An argument beginning with ~ is a filename to be expanded."
   (when (and (not eshell-current-argument)
+             (not eshell-current-quoted)
              (eq (char-after) ?~))
     ;; Apply this modifier fairly early so it happens before things
     ;; like glob expansion.
index 2f170fb0c63e1ae609597f6facbc673162333f98..9789e519f4c24e2adcf34506fd45cb446dd8bcc5 100644 (file)
@@ -34,6 +34,9 @@
                                                     default-directory))))
 ;;; Tests:
 
+\f
+;; Variables
+
 (ert-deftest em-dirs-test/pwd-var ()
   "Test using the $PWD variable."
   (let ((default-directory "/some/path"))
      (eshell-match-command-output "echo $-[1][/ 1 3]"
                                   "(\"some\" \"here\")\n"))))
 
+\f
+;; Argument expansion
+
+(ert-deftest em-dirs-test/expand-user-reference/local ()
+  "Test expansion of \"~USER\" references."
+  (eshell-command-result-equal "echo ~" (expand-file-name "~"))
+  (eshell-command-result-equal
+   (format "echo ~%s" user-login-name)
+   (expand-file-name (format "~%s" user-login-name))))
+
+(ert-deftest em-dirs-test/expand-user-reference/quoted ()
+  "Test that a quoted \"~\" isn't expanded."
+  (eshell-command-result-equal "echo \\~" "~")
+  (eshell-command-result-equal "echo \"~\"" "~")
+  (eshell-command-result-equal "echo '~'" "~"))
+
+\f
+;; `cd'
+
 (ert-deftest em-dirs-test/cd ()
   "Test that changing directories with `cd' works."
   (ert-with-temp-directory tmpdir