Subject: Re: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable.

From: Antero Mejr <[email-masked]>
Date: Thu, 11 May 2023 20:11:16 +0000

Eli Zaretskii <[email-masked]> writes:

>> > This actually means that I misunderstood the code.  Now that I see the
>> > truth, why is it a good idea to compare directories case-sensitively
>> > when the filesystem is not?  That's not something users will expect.
>> 
>> To accurately assess if a directory name matches with possible
>> case-sensitivity, the process would be:
>> 1. check the case-sensitivity of the filesystem
>> 2. If case insensitive, check the case-sensitivity of each subdirectory
>> (using Windows queryCaseSensitiveInfo if applicable)
>> 3. map over the components of the directory name, checking each subdirectory
>> with the correct case-sensitivity setting
>
> We already have all that in file-equal-p.  We should just use is
> there.

Ok, patch is attached (tested on FAT32 disk).

>From 338629b4dc6da17460c96a19178307e6db4bd5d8 Mon Sep 17 00:00:00 2001
From: Antero Mejr <[email-masked]>
Date: Thu, 11 May 2023 19:22:49 +0000
Subject: [PATCH] Handle case-insensitivity for
 safe-local-variable-directories.

* lisp/emacs-lisp/files.el (hack-local-variables-filter): Use
file-equal-p when checking safe-local-variable-directories.
* doc/lispref/variables.texi (File Local Variables): Remove sentence
in safe-local-variable-directories description about unusual
case-sensitivity behavior.  (Bug#61901)
---
 doc/lispref/variables.texi | 4 +---
 lisp/files.el              | 4 +++-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index b3a8cd8110c..d8f0ad489bc 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -1984,9 +1984,7 @@ such as the variables in @file{.dir-locals.el}, will be enabled even
 if they are risky.  The directories in this list must be
 fully-expanded absolute file names that end in a directory separator
 character.  They may also be remote directories if the variable
-@code{enable-remote-dir-locals} is set non-@code{nil}.  Directories in
-this list are matched case-sensitively, even if the filesystem is
-case-sensitive.
+@code{enable-remote-dir-locals} is set non-@code{nil}.
 @end defvar
 
 @defun hack-local-variables &optional handle-mode
diff --git a/lisp/files.el b/lisp/files.el
index 35d794f6dcf..a3e7e2bd65d 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3934,7 +3934,9 @@ DIR-NAME is the name of the associated directory.  Otherwise it is nil."
 		  (null unsafe-vars)
 		  (null risky-vars))
 	     (memq enable-local-variables '(:all :safe))
-             (member dir-name safe-local-variable-directories)
+             (delq nil (mapcar (lambda (dir)
+                                 (file-equal-p dir dir-name))
+                               safe-local-variable-directories))
 	     (hack-local-variables-confirm all-vars unsafe-vars
 					   risky-vars dir-name))
 	 (dolist (elt all-vars)
-- 
2.39.2