From 56cec5109bfe88b36ce5778e9fa5e7d26b0552a9 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sat, 26 Oct 2024 14:22:38 -0700 Subject: [PATCH] ; 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. (cherry picked from commit d6fe32e531044b518ae5b6b39377378cbf13292d) --- lisp/eshell/em-glob.el | 5 +++- lisp/eshell/esh-util.el | 2 +- test/lisp/eshell/esh-util-tests.el | 40 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lisp/eshell/em-glob.el b/lisp/eshell/em-glob.el index 42373b8b8c0..56b6cd3fae7 100644 --- a/lisp/eshell/em-glob.el +++ b/lisp/eshell/em-glob.el @@ -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. diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 180f049e495..65e19228e0e 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -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) diff --git a/test/lisp/eshell/esh-util-tests.el b/test/lisp/eshell/esh-util-tests.el index 4a0874bff39..b2fd01e0c29 100644 --- a/test/lisp/eshell/esh-util-tests.el +++ b/test/lisp/eshell/esh-util-tests.el @@ -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 -- 2.39.5