From 61ced3cafda493cf2815500ee7c656e5318e7e21 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Tue, 22 Oct 2024 09:43:00 -0700 Subject: [PATCH] Fix error when splicing Eshell globs and a glob expands to itself This could happen when 'eshell-extended-glob' determines that a "glob" is not really a glob. This mainly happens for remote file names with a "~" in them, like "/ssh:remote:~/file.txt". * lisp/eshell/em-glob.el (eshell-extended-glob): Return a list when 'eshell-glob-splice-results' is non-nil. * test/lisp/eshell/em-glob-tests.el (em-glob-test/expand/splice-results) em-glob-test/expand/no-splice-results): Extend tests. (cherry picked from commit b7a375f5c49ac86399b9af7a6a74720ed294abd7) --- lisp/eshell/em-glob.el | 2 +- test/lisp/eshell/em-glob-tests.el | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lisp/eshell/em-glob.el b/lisp/eshell/em-glob.el index b95204c7e1e..42373b8b8c0 100644 --- a/lisp/eshell/em-glob.el +++ b/lisp/eshell/em-glob.el @@ -348,7 +348,7 @@ regular expressions, and these cannot support the above constructs." ;; always be sure if the "~" is a home directory reference or ;; part of a glob (e.g. if the argument was assembled from ;; variables). - glob + (if eshell-glob-splice-results (list glob) glob) (unwind-protect (apply #'eshell-glob-entries globs) (if message-shown diff --git a/test/lisp/eshell/em-glob-tests.el b/test/lisp/eshell/em-glob-tests.el index 2efb3a9df69..88e9cc73bbd 100644 --- a/test/lisp/eshell/em-glob-tests.el +++ b/test/lisp/eshell/em-glob-tests.el @@ -74,7 +74,13 @@ component ending in \"symlink\" is treated as a symbolic link." ;; Ensure the default expansion splices the glob. (eshell-command-result-equal "funcall list *.el" '("a.el" "b.el")) (eshell-command-result-equal "funcall list *.txt" '("c.txt")) - (eshell-command-result-equal "funcall list *.no" '("*.no"))))) + ;; When spliting, no-matches cases also return a list containing + ;; the original non-matching glob. + (eshell-command-result-equal "funcall list *.no" '("*.no")) + (when (eshell-tests-remote-accessible-p) + (let ((remote (file-remote-p ert-remote-temporary-file-directory))) + (eshell-command-result-equal (format "funcall list %s~/a.el" remote) + `(,(format "%s~/a.el" remote)))))))) (ert-deftest em-glob-test/expand/no-splice-results () "Test that globs are treated as lists when @@ -85,9 +91,13 @@ component ending in \"symlink\" is treated as a symbolic link." ;; Ensure the default expansion splices the glob. (eshell-command-result-equal "funcall list *.el" '(("a.el" "b.el"))) (eshell-command-result-equal "funcall list *.txt" '(("c.txt"))) - ;; The no-matches case is special here: the glob is just the + ;; The no-matches cases are special here: the glob is just the ;; string, not the list of results. - (eshell-command-result-equal "funcall list *.no" '("*.no"))))) + (eshell-command-result-equal "funcall list *.no" '("*.no")) + (when (eshell-tests-remote-accessible-p) + (let ((remote (file-remote-p ert-remote-temporary-file-directory))) + (eshell-command-result-equal (format "funcall list %s~/a.el" remote) + `(,(format "%s~/a.el" remote)))))))) (ert-deftest em-glob-test/expand/explicitly-splice-results () "Test explicitly splicing globs works the same no matter the -- 2.39.5