]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Bug#35241
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 17 Apr 2019 12:04:37 +0000 (14:04 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Wed, 17 Apr 2019 12:04:37 +0000 (14:04 +0200)
* lisp/files.el (executable-find): Quote default-directory.  (Bug#35241)

* test/lisp/files-tests.el (files-tests-executable-find): New test.

lisp/files.el
test/lisp/files-tests.el

index b81550e297ca53443d492292f3dbe0765e1a4f1c..c05d70a00ecb1568d5d3a60f6478310ed0df6f1e 100644 (file)
@@ -1058,7 +1058,8 @@ REMOTE is non-nil, search on the remote host indicated by
         (when (stringp res) (file-local-name res)))
     ;; Use 1 rather than file-executable-p to better match the
     ;; behavior of call-process.
-    (locate-file command exec-path exec-suffixes 1)))
+    (let ((default-directory (file-name-quote default-directory 'top)))
+      (locate-file command exec-path exec-suffixes 1))))
 
 (defun load-library (library)
   "Load the Emacs Lisp library named LIBRARY.
index 13e8bb4943c2db98b0ba2b04b4b86a0797c92de5..53e6e9064a18cb790f51d56abd51a10ee8d57540 100644 (file)
@@ -1218,5 +1218,31 @@ See <https://debbugs.gnu.org/19657#20>."
                                     process-environment)))
     (should (equal old (file-truename (abbreviate-file-name testfile))))))
 
+(ert-deftest files-tests-executable-find ()
+  "Test that `executable-find' works also with a relative or remote PATH.
+See <https://debbugs.gnu.org/35241>."
+  (let ((tmpfile (make-temp-file "files-test")))
+    (unwind-protect
+        (progn
+          (set-file-modes tmpfile #o777)
+          (let ((exec-path `(,temporary-file-directory)))
+            (should
+             (equal tmpfile
+                    (executable-find (file-name-nondirectory tmpfile)))))
+          ;; An empty element of `exec-path' means `default-directory'.
+          (let ((default-directory temporary-file-directory)
+                (exec-path nil))
+            (should
+             (equal tmpfile
+                    (executable-find (file-name-nondirectory tmpfile)))))
+          ;; The remote file name shall be quoted, and handled like a
+          ;; non-existing directory.
+          (let ((default-directory "/ssh::")
+                (exec-path (append exec-path `("." ,temporary-file-directory))))
+            (should
+             (equal tmpfile
+                    (executable-find (file-name-nondirectory tmpfile))))))
+      (delete-file tmpfile))))
+
 (provide 'files-tests)
 ;;; files-tests.el ends here