emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 76098d3 1/4: Do not truncate /foo//bar to /bar/ in parse-colon-pa


From: Lars Ingebrigtsen
Subject: master 76098d3 1/4: Do not truncate /foo//bar to /bar/ in parse-colon-path
Date: Wed, 12 Aug 2020 12:09:36 -0400 (EDT)

branch: master
commit 76098d39c992aa51f5bdb04fb39e40fc5eb409d5
Author: Tino Calancha <tino.calancha@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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).
---
 lisp/files.el            | 14 ++++++++++----
 test/lisp/files-tests.el |  5 ++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 1909669..9270f33 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 4b902fd..5b2f5fd 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 <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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]