; Ensure 'eshell-split-filename' doesn't expand the filename first

* 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.
This commit is contained in:
Jim Porter 2024-10-26 14:22:38 -07:00
parent 02510606f6
commit d6fe32e531
3 changed files with 45 additions and 2 deletions

View 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.

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

View file

@ -183,4 +183,44 @@
(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