emacs-diffs
[Top][All Lists]
Advanced

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

master 6791165b2a: Fix file-name-case-insensitive-p in ffap (bug#56443)


From: Mattias Engdegård
Subject: master 6791165b2a: Fix file-name-case-insensitive-p in ffap (bug#56443)
Date: Fri, 8 Jul 2022 09:14:34 -0400 (EDT)

branch: master
commit 6791165b2a0e707f719efec08aad62cdf6ed8ad3
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Fix file-name-case-insensitive-p in ffap (bug#56443)
    
    Don't crash if the file name argument to file-name-case-insensitive-p,
    after expansion, doesn't have a parent directory.  This occurs
    when calling ffap on something that looks like an email address.
    
    * src/fileio.c (Ffile_name_case_insensitive_p): Return nil if no file
    or parent directory could be found.
    * test/src/fileio-tests.el (fileio-tests--identity-expand-handler)
    (fileio--file-name-case-insensitive-p): New test.
---
 src/fileio.c             |  6 +++---
 test/src/fileio-tests.el | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/fileio.c b/src/fileio.c
index d07e62a121..9697f6c8cf 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2601,9 +2601,9 @@ is case-insensitive.  */)
       if (err <= 0)
        return err < 0 ? Qt : Qnil;
       Lisp_Object parent = file_name_directory (filename);
-      /* Avoid infinite loop if the root has trouble
-        (impossible?).  */
-      if (!NILP (Fstring_equal (parent, filename)))
+      /* Avoid infinite loop if the root has trouble (if that's even possible).
+        Without a parent, we just don't know and return nil as well.  */
+      if (!STRINGP (parent) || !NILP (Fstring_equal (parent, filename)))
        return Qnil;
       filename = parent;
     }
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
index c137ce06f1..08582c8a86 100644
--- a/test/src/fileio-tests.el
+++ b/test/src/fileio-tests.el
@@ -201,4 +201,20 @@ Also check that an encoding error can appear in a symlink."
     (insert-file-contents "/dev/urandom" nil nil 10)
     (should (= (buffer-size) 10))))
 
+(defun fileio-tests--identity-expand-handler (_ file &rest _)
+  file)
+(put 'fileio-tests--identity-expand-handler 'operations '(expand-file-name))
+
+(ert-deftest fileio--file-name-case-insensitive-p ()
+  ;; Check that we at least don't crash if given nonexisting files
+  ;; without a directory (bug#56443).
+
+  ;; Use an identity file-name handler, as if called by `ffap'.
+  (let* ((file-name-handler-alist
+          '(("^mailto:"; . fileio-tests--identity-expand-handler)))
+         (file "mailto:snowball@hell.com";))
+    ;; Check that `expand-file-name' is identity for this name.
+    (should (equal (expand-file-name file nil) file))
+    (file-name-case-insensitive-p file)))
+
 ;;; fileio-tests.el ends here



reply via email to

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