]> git.eshelyaron.com Git - emacs.git/commitdiff
; Ensure 'eshell-split-filename' doesn't expand the filename first
authorJim Porter <jporterbugs@gmail.com>
Sat, 26 Oct 2024 21:22:38 +0000 (14:22 -0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 29 Oct 2024 09:52:26 +0000 (10:52 +0100)
* lisp/eshell/esh-util.el (eshell-split-filename): Never expand the
filename.

* lisp/eshell/em-glob.el (eshell-glob-p): A leading "~" isn't a globbing
character.

* test/lisp/eshell/esh-util-tests.el
(esh-util-test/split-filename/absolute)
(esh-util-test/split-filename/relative)
(esh-util-test/split-filename/user)
(esh-util-test/split-filename/remote-absolute)
(esh-util-test/split-filename/remote-relative)
(esh-util-test/split-filename/remote-user): New tests.

(cherry picked from commit d6fe32e531044b518ae5b6b39377378cbf13292d)

lisp/eshell/em-glob.el
lisp/eshell/esh-util.el
test/lisp/eshell/esh-util-tests.el

index 42373b8b8c0ca254898bc3dadf076396ca1c2633..56b6cd3fae75e34bd0579c36519250bdee34a87c 100644 (file)
@@ -244,7 +244,10 @@ resulting regular expression."
 
 (defun eshell-glob-p (pattern)
   "Return non-nil if PATTERN has any special glob characters."
-  (string-match (eshell-glob-chars-regexp) pattern))
+  ;; "~" is an infix globbing character, so one at the start of a glob
+  ;; must be a literal.
+  (let ((start (if (string-prefix-p "~" pattern) 1 0)))
+    (string-match (eshell-glob-chars-regexp) pattern start)))
 
 (defun eshell-glob-convert-1 (glob &optional last)
   "Convert a GLOB matching a single element of a file name to regexps.
index 180f049e495ed542512aa22e07a4b66a5302321f..65e19228e0e04ec03989382288d4ff2cac7b6cde 100644 (file)
@@ -462,7 +462,7 @@ Prepend remote identification of `default-directory', if any."
 (defun eshell-split-filename (filename)
   "Split a FILENAME into a list of file/directory components."
   (let* ((remote (file-remote-p filename))
-         (filename (file-local-name filename))
+         (filename (or (file-remote-p filename 'localname 'never) filename))
          (len (length filename))
          (index 0) (curr-start 0)
          parts)
index 4a0874bff3914f7bf3f2abaa670876024a671f35..b2fd01e0c293f2d2d33e212da4e890e1956f70bf 100644 (file)
     (should (equal (eshell-get-path 'literal)
                    expected-path))))
 
+(ert-deftest esh-util-test/split-filename/absolute ()
+  "Test splitting an absolute filename."
+  (should (equal (eshell-split-filename "/foo/bar/file.txt")
+                 '("/" "foo/" "bar/" "file.txt"))))
+
+(ert-deftest esh-util-test/split-filename/relative ()
+  "Test splitting a relative filename."
+  (should (equal (eshell-split-filename "foo/bar/file.txt")
+                 '("foo/" "bar/" "file.txt"))))
+
+(ert-deftest esh-util-test/split-filename/user ()
+  "Test splitting a user filename."
+  (should (equal (eshell-split-filename "~/file.txt")
+                 '("~/" "file.txt")))
+  (should (equal (eshell-split-filename "~user/file.txt")
+                 '("~user/" "file.txt"))))
+
+(ert-deftest esh-util-test/split-filename/remote-absolute ()
+  "Test splitting a remote absolute filename."
+  (skip-unless (eshell-tests-remote-accessible-p))
+  (let ((remote (file-remote-p ert-remote-temporary-file-directory)))
+    (should (equal (eshell-split-filename (format "%s/foo/bar/file.txt" remote))
+                   `(,remote "/" "foo/" "bar/" "file.txt")))))
+
+(ert-deftest esh-util-test/split-filename/remote-relative ()
+  "Test splitting a remote relative filename."
+  (skip-unless (eshell-tests-remote-accessible-p))
+  (let ((remote (file-remote-p ert-remote-temporary-file-directory)))
+    (should (equal (eshell-split-filename (format "%sfoo/bar/file.txt" remote))
+                   `(,remote "foo/" "bar/" "file.txt")))))
+
+(ert-deftest esh-util-test/split-filename/remote-user ()
+  "Test splitting a remote user filename."
+  (skip-unless (eshell-tests-remote-accessible-p))
+  (let ((remote (file-remote-p ert-remote-temporary-file-directory)))
+    (should (equal (eshell-split-filename (format "%s~/file.txt" remote))
+                   `(,remote "~/" "file.txt")))
+    (should (equal (eshell-split-filename (format "%s~user/file.txt" remote))
+                   `(,remote "~user/" "file.txt")))))
+
 ;;; esh-util-tests.el ends here