From: Tino Calancha Date: Wed, 12 Aug 2020 12:53:29 +0000 (+0200) Subject: Do not truncate /foo//bar to /bar/ in parse-colon-path X-Git-Tag: emacs-28.0.90~6657 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=76098d39c992aa51f5bdb04fb39e40fc5eb409d5;p=emacs.git Do not truncate /foo//bar to /bar/ in parse-colon-path * lisp/files.el (parse-colon-path): Use substitute-env-vars and expand-file-name instead of substitute-in-file-name (Bug#21454). --- diff --git a/lisp/files.el b/lisp/files.el index 19096693461..9270f334afa 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -752,10 +752,16 @@ resulting list of directory names. For an empty path element (i.e., a leading or trailing separator, or two adjacent separators), return nil (meaning `default-directory') as the associated list element." (when (stringp search-path) - (mapcar (lambda (f) - (if (equal "" f) nil - (substitute-in-file-name (file-name-as-directory f)))) - (split-string search-path path-separator)))) + (let ((spath (substitute-env-vars search-path))) + (mapcar (lambda (f) + (if (equal "" f) nil + (let ((dir (expand-file-name (file-name-as-directory f)))) + ;; Previous implementation used `substitute-in-file-name' + ;; which collapse multiple "/" in front. Do the same for + ;; backward compatibility. + (if (string-match "\\`/+" dir) + (substring dir (1- (match-end 0))) dir)))) + (split-string spath path-separator))))) (defun cd-absolute (dir) "Change current directory to given absolute file name DIR." diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 4b902fd82ae..5b2f5fd6f0f 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -190,7 +190,6 @@ form.") (ert-deftest files-tests-bug-21454 () "Test for https://debbugs.gnu.org/21454 ." - :expected-result :failed (let ((input-result '(("/foo/bar//baz/:/bar/foo/baz//" nil ("/foo/bar/baz/" "/bar/foo/baz/")) ("/foo/bar/:/bar/qux/:/qux/foo" nil ("/foo/bar/" "/bar/qux/" "/qux/foo/")) @@ -1362,5 +1361,9 @@ See ." (normal-mode) (should (not (eq major-mode 'text-mode)))))) +(ert-deftest files-colon-path () + (should (equal (parse-colon-path "/foo//bar/baz") + '("/foo/bar/baz/")))) + (provide 'files-tests) ;;; files-tests.el ends here