emacs-diffs
[Top][All Lists]
Advanced

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

master f729c333c7 2/3: Don't have ffap interpret ":/bin" as the current


From: Lars Ingebrigtsen
Subject: master f729c333c7 2/3: Don't have ffap interpret ":/bin" as the current directory
Date: Fri, 14 Jan 2022 05:51:39 -0500 (EST)

branch: master
commit f729c333c7ae6d159e4af510b21e0fd031786bd1
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Don't have ffap interpret ":/bin" as the current directory
    
    * lisp/ffap.el (ffap-file-at-point): Don't interpret :/bin as the
    current directory (bug#52441).
---
 lisp/ffap.el            | 11 +++++++----
 test/lisp/ffap-tests.el | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lisp/ffap.el b/lisp/ffap.el
index f9220817a7..b5d2a02cd1 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1449,10 +1449,13 @@ which may actually result in an URL rather than a 
filename."
               (ffap-file-exists-string (substring name 0 (match-beginning 
0)))))
         ;; If it contains a colon, get rid of it (and return if exists)
         ((and (string-match path-separator name)
-              (setq name (ffap-string-at-point 'nocolon))
-              (> (length name) 0)
-              (ffap-file-exists-string name)))
-        ;; File does not exist, try the alist:
+              (let ((this-name (ffap-string-at-point 'nocolon)))
+                 ;; But don't interpret the first part if ":/bin" as
+                 ;; the empty string.
+                (when (> (length this-name) 0)
+                   (setq name this-name)
+                  (ffap-file-exists-string name)))))
+         ;; File does not exist, try the alist:
         ((let ((alist ffap-alist) tem try case-fold-search)
            (while (and alist (not try))
              (setq tem (car alist) alist (cdr alist))
diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el
index aebc9b6dbb..c5032a60a1 100644
--- a/test/lisp/ffap-tests.el
+++ b/test/lisp/ffap-tests.el
@@ -141,6 +141,21 @@ left alone when opening a URL in an external browser."
         (let (kill-buffer-query-functions)
           (kill-buffer (call-interactively #'find-file-at-point)))))))
 
+(ert-deftest ffap-test-path ()
+  (with-temp-buffer
+    (insert "/usr/bin:/bin")
+    (goto-char (point-min))
+    (should (equal (ffap-file-at-point) "/usr/bin")))
+  (with-temp-buffer
+    (insert "/usr/bin:/bin")
+    (goto-char (point-min))
+    (search-forward ":")
+    (should (equal (ffap-file-at-point) "/bin")))
+  (with-temp-buffer
+    (insert ":/bin")
+    (goto-char (point-min))
+    (should (equal (ffap-file-at-point) nil))))
+
 (provide 'ffap-tests)
 
 ;;; ffap-tests.el ends here



reply via email to

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