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).
This commit is contained in:
Tino Calancha 2020-08-12 14:53:29 +02:00 committed by Lars Ingebrigtsen
parent a5a0a9c9ca
commit 76098d39c9
2 changed files with 14 additions and 5 deletions

View file

@ -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."

View file

@ -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 <https://debbugs.gnu.org/36401>."
(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