From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Mar 2023 22:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 61901@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.167770986311007 (code B ref -1); Wed, 01 Mar 2023 22:32:02 +0000 Received: (at submit) by debbugs.gnu.org; 1 Mar 2023 22:31:03 +0000 Received: from localhost ([127.0.0.1]:55211 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXUyU-0002rI-CO for submit@debbugs.gnu.org; Wed, 01 Mar 2023 17:31:02 -0500 Received: from lists.gnu.org ([209.51.188.17]:36388) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXUyS-0002r3-Ci for submit@debbugs.gnu.org; Wed, 01 Mar 2023 17:31:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXUyS-0005XM-6I for bug-gnu-emacs@gnu.org; Wed, 01 Mar 2023 17:31:00 -0500 Received: from mout-p-101.mailbox.org ([80.241.56.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1pXUyP-00053u-PB for bug-gnu-emacs@gnu.org; Wed, 01 Mar 2023 17:30:59 -0500 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4PRppS4XlDz9sSS for ; Wed, 1 Mar 2023 23:30:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1677709824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=K9lD2zACD9/PmXIuMYcRDKjp/UzoQ9ullRVNcrRxaBk=; b=KJ6xHaHX3BWKFNkaQXocKluzJxhg4OEz+KdbxBAR3yLU6wKVJgzr44ds3GCDHLS/3MtFFx DM0UPhv9uib1JvLfKIxwxlxv/vEIrqXSY1rXMS3ekZzLSTIckhN4c+nupgPRTIwIB2S0G5 fA/86g6audaSpT5Jyc4hSYV86Q190hEmx5nALAqTWfBC5yPQhSn5sMctnZBUYlVaXojVv3 GEA1M+5kVUR/lvTkXncE+hzAV2Ek8oPE2wV8YQDkJ2GmgLpZin5vPgyaOhDMLMfCgPg+E6 2+OLQT1eCr8DfagARXGEmzGNMXJ5yCJETrWmRVNvAi9n2rOQ53m7gzY3r9SHIA== From: Antero Mejr Date: Wed, 01 Mar 2023 22:20:33 +0000 Message-ID: <87sfeoksuk.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-META: hrggins9umdge4xsoz6jg36j9y6ogmcj X-MBO-RS-ID: 1c79a36e36ecc3d0473 Received-SPF: pass client-ip=80.241.56.151; envelope-from=antero@mailbox.org; helo=mout-p-101.mailbox.org X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain This patch allows users to trust directories to load dir-local variables from, so they don't have to do something lile this: (defun risky-local-variable-p (sym &optional _ignored) nil) as suggested here: https://emacs.stackexchange.com/questions/10983/remember-permission-to-execute-risky-local-variables It also works over TRAMP if enable-remote-dir-locals is true. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-permanently-enabled-local-variable-dirs-variable.patch >From 93494f5beb4b51d989ea87755c077379458ffb04 Mon Sep 17 00:00:00 2001 From: Antero Mejr Date: Wed, 1 Mar 2023 21:59:57 +0000 Subject: [PATCH] Add permanently-enabled-local-variable-dirs variable. This variable can be set to automatically load risky dir-local variables from a list of trusted directories. * lisp/emacs-lisp/files.el (permanently-enabled-local-variable-dirs, hack-local-variables-filter, hack-local-variables-confirm): New variable and associated logic. * test/lisp/files-tests.el (files-tests-permanently-enabled-local-variable-dirs): Add tests for same. * doc/lispref/variables.texi (File Local Variables): Add documentation for same. * etc/NEWS (Lisp Changes in Emacs 30.1): Add news entry for same. --- doc/lispref/variables.texi | 6 ++++++ etc/NEWS | 5 +++++ lisp/files.el | 27 ++++++++++++++++++++++----- test/lisp/files-tests.el | 22 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 5584cbce9a6..47cfb824dcb 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1974,6 +1974,12 @@ File Local Variables symbols. @end defvar +@defvar permanently-enabled-local-variable-dirs +This is a list of trusted directories that contain local variables. +Local variables in these directories will always be enabled, regardless +of whether they are risky. +@end defvar + @defun hack-local-variables &optional handle-mode This function parses, and binds or evaluates as appropriate, any local variables specified by the contents of the current buffer. The variable diff --git a/etc/NEWS b/etc/NEWS index 31fb22fc1e2..cc5198a903b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -238,6 +238,11 @@ hooks named after the feature name, like 'esh-mode-unload-hook'. * Lisp Changes in Emacs 30.1 ++++ +** New variable 'permanently-enabled-local-variable-dirs'. +This variable is used to to permanently trust directories containing +risky directory-local variables. + ** Functions and variables to transpose sexps +++ diff --git a/lisp/files.el b/lisp/files.el index 387a3b5dc66..bde126375ae 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -681,7 +681,8 @@ enable-local-variables always obeys file local variable specifications and the -*- line, and ignores this variable. -Also see the `permanently-enabled-local-variables' variable." +Also see the `permanently-enabled-local-variables' and +'permanently-enabled-local-variable-dirs' variables." :risky t :type '(choice (const :tag "Query Unsafe" t) (const :tag "Safe Only" :safe) @@ -3692,6 +3693,14 @@ permanently-enabled-local-variables "A list of file-local variables that are always enabled. This overrides any `enable-local-variables' setting.") +(defcustom permanently-enabled-local-variable-dirs '() + "A list of directories that contain local variables that are always +enabled, regardless of whether they are risky." + :version "30.1" + :type '(repeat string) + :risky t + :group 'find-file) + (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name) "Get confirmation before setting up local variable values. ALL-VARS is the list of all variables to be set up. @@ -3730,7 +3739,9 @@ hack-local-variables-confirm ! -- to apply the local variables list, and permanently mark these values (*) as safe (in the future, they will be set automatically.) i -- to ignore the local variables list, and permanently mark these - values (*) as ignored\n\n") + values (*) as ignored ++ -- to apply the local variables list, and permanently trust " + name "\n\n") (insert "\n\n")) (dolist (elt all-vars) (cond ((member elt unsafe-vars) @@ -3754,7 +3765,7 @@ hack-local-variables-confirm (pop-to-buffer buf '(display-buffer--maybe-at-bottom)) (let* ((exit-chars '(?y ?n ?\s)) (prompt (format "Please type %s%s: " - (if offer-save "y, n, ! or i" "y or n") + (if offer-save "y, n, !, i, or +" "y or n") (if (< (line-number-at-pos (point-max)) (window-body-height)) "" @@ -3762,8 +3773,13 @@ hack-local-variables-confirm char) (when offer-save (push ?i exit-chars) - (push ?! exit-chars)) + (push ?! exit-chars) + (push ?+ exit-chars)) (setq char (read-char-choice prompt exit-chars)) + (when (and offer-save (= char ?+)) + (customize-push-and-save + 'permanently-enabled-local-variable-dirs + (list dir-name))) (when (and offer-save (or (= char ?!) (= char ?i)) unsafe-vars) @@ -3772,7 +3788,7 @@ hack-local-variables-confirm 'safe-local-variable-values 'ignored-local-variable-values) unsafe-vars)) - (prog1 (memq char '(?! ?\s ?y)) + (prog1 (memq char '(?! ?\s ?y ?+)) (quit-window t))))))) (defconst hack-local-variable-regexp @@ -3904,6 +3920,7 @@ hack-local-variables-filter (null unsafe-vars) (null risky-vars)) (memq enable-local-variables '(:all :safe)) + (member dir-name permanently-enabled-local-variable-dirs) (hack-local-variables-confirm all-vars unsafe-vars risky-vars dir-name)) (dolist (elt all-vars) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index aadb60e1de7..95eaf9a6bd0 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -166,6 +166,28 @@ files-tests-permanent-local-variables (hack-local-variables) (should (eq lexical-binding nil))))) +(ert-deftest files-tests-permanently-enabled-local-variable-dirs () + ;; permanently-enabled-local-variable-dirs should be risky, + ;; so use it as an arbitrary risky variable. + (let ((test-alist '((permanently-enabled-local-variable-dirs + . "some_val"))) + (fakedir "test1/test2") + (enable-local-eval t)) + (with-temp-buffer + (setq permanently-enabled-local-variable-dirs (list fakedir)) + (hack-local-variables-filter test-alist fakedir) + (should (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq permanently-enabled-local-variable-dirs (list fakedir)) + (setq noninteractive t) + (hack-local-variables-filter test-alist "wrong") + (should-not (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq permanently-enabled-local-variable-dirs '()) + (setq noninteractive t) + (hack-local-variables-filter test-alist fakedir) + (should-not (equal file-local-variables-alist test-alist))))) + (defvar files-test-bug-18141-file (ert-resource-file "files-bug18141.el.gz") "Test file for bug#18141.") -- 2.38.1 --=-=-=-- From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Mar 2023 06:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.16777402336063 (code B ref 61901); Thu, 02 Mar 2023 06:58:02 +0000 Received: (at 61901) by debbugs.gnu.org; 2 Mar 2023 06:57:13 +0000 Received: from localhost ([127.0.0.1]:55640 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXcsL-0001Zj-1o for submit@debbugs.gnu.org; Thu, 02 Mar 2023 01:57:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56196) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXcsJ-0001ZX-QP for 61901@debbugs.gnu.org; Thu, 02 Mar 2023 01:57:12 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXcsE-0000qn-2n; Thu, 02 Mar 2023 01:57:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=iE9iae6A3Vz4EqqD2pb8vg7Bs7iMO4mc4QK9gaec19U=; b=PH+Wq5VRO8DK zBZStwNUpd8xau8ShkhDi/bk0rMSG4toqH+ALDPVFXWP1lr8v3nfl9LuuOVfrAr6F5wQ3JdngitD0 7D5SerK0kMOut5kCN/H8XvL6DU3WzxJy2UYWt5Bkp14WQLDqL9frpHdzxNMX482ZsdzG0BIUBpzS3 T4rnzgRCIEoxNfc4uPmf9JHTyN+PfH/jH6SWseLYjy12oEWdwVRoJ9LvD1VwYZLC6wTsVYSNmKryP FMyMia3A6OCblQzM5KezwOtQDHFm/hhS0Y3OrSFv+l5zoy6N/ACGFJnU7pBxLhcCXYmbVKj3gSjgO KaIG9N55ksW6U7RQRrNwJA==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXcsD-00047E-JE; Thu, 02 Mar 2023 01:57:05 -0500 Date: Thu, 02 Mar 2023 08:57:21 +0200 Message-Id: <83wn3zej3i.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87sfeoksuk.fsf@mailbox.org> (bug-gnu-emacs@gnu.org) References: <87sfeoksuk.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Wed, 01 Mar 2023 22:20:33 +0000 > From: Antero Mejr via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > This patch allows users to trust directories to load dir-local variables > from, so they don't have to do something lile this: > (defun risky-local-variable-p (sym &optional _ignored) nil) > as suggested here: > https://emacs.stackexchange.com/questions/10983/remember-permission-to-execute-risky-local-variables > > It also works over TRAMP if enable-remote-dir-locals is true. Thanks, IMO this is a very useful feature. > --- a/doc/lispref/variables.texi > +++ b/doc/lispref/variables.texi > @@ -1974,6 +1974,12 @@ File Local Variables > symbols. > @end defvar > > +@defvar permanently-enabled-local-variable-dirs > +This is a list of trusted directories that contain local variables. > +Local variables in these directories will always be enabled, regardless > +of whether they are risky. > +@end defvar This should explicitly allude to the '.dir-locals.el' files in those directories, since otherwise talking about "directories that contain variables" could be confusing. I also suggest to rename the variable to something like 'permanently-safe-local-variable-directories', or maybe just 'safe-local-variable-directories' which IMO should express the purpose better. > -Also see the `permanently-enabled-local-variables' variable." > +Also see the `permanently-enabled-local-variables' and > +'permanently-enabled-local-variable-dirs' variables." ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We quote `like this' in doc strings, to produce links in the *Help* buffers. > +(defcustom permanently-enabled-local-variable-dirs '() > + "A list of directories that contain local variables that are always > +enabled, regardless of whether they are risky." The first line of a doc string should be a single complete sentence. (This is because the various apropos commands show only the first line of the doc string.) > @@ -3730,7 +3739,9 @@ hack-local-variables-confirm > ! -- to apply the local variables list, and permanently mark these > values (*) as safe (in the future, they will be set automatically.) > i -- to ignore the local variables list, and permanently mark these > - values (*) as ignored\n\n") > + values (*) as ignored > ++ -- to apply the local variables list, and permanently trust " > + name "\n\n") "permanently trust name" sounds confusing (what is "name"?). How about this variant: + -- to apply the local variables list, and permanently trust all directory-local variables in this directory > @@ -3762,8 +3773,13 @@ hack-local-variables-confirm > char) > (when offer-save > (push ?i exit-chars) > - (push ?! exit-chars)) > + (push ?! exit-chars) > + (push ?+ exit-chars)) > (setq char (read-char-choice prompt exit-chars)) > + (when (and offer-save (= char ?+)) > + (customize-push-and-save > + 'permanently-enabled-local-variable-dirs > + (list dir-name))) Bother: AFAIU here we modify the user's custom file without asking for an explicit permission. Should we ask for permission? Last, but not least: this change is larger than what we can accept without you assigning to FSF the copyright for your changes, and I don't see any copyright assignment in your name on file. Would you be willing to do the legal paperwork for such an assignment? If yes, I will send you the form to start the paperwork rolling; when it is completed, we can install your changes. Thanks. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Mar 2023 17:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: Antero Mejr , 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.167777814029668 (code B ref 61901); Thu, 02 Mar 2023 17:29:02 +0000 Received: (at 61901) by debbugs.gnu.org; 2 Mar 2023 17:29:00 +0000 Received: from localhost ([127.0.0.1]:58302 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXmjj-0007iS-Qu for submit@debbugs.gnu.org; Thu, 02 Mar 2023 12:29:00 -0500 Received: from mout-p-102.mailbox.org ([80.241.56.152]:46788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXmjh-0007iF-OG for 61901@debbugs.gnu.org; Thu, 02 Mar 2023 12:28:58 -0500 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4PSJ421Z0Zz9sbr; Thu, 2 Mar 2023 18:28:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1677778130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DtEiYG9S9D5IyNsFdcoLZTFhJf3ekH4/EF0Gwkcs6og=; b=xUZqzBh5LRS/AQhS+TYx+UJSOI5/8L21m0srQKOrYCnsl8A9sRrEv/utD1Nto3XqH7gHDN /2tgkFHMTvVE/kcbeoqzWYKxYr+NBOkdtdQ58VZFx1C9tGELxO2T8ItCG6b9ySEHfr1olo r1LmqWd+JV/KittS5el8uQ2lMaCQvLP8I5FTCTu01n1iJIk+Yrl5bTMNwI7UD6FcGCZk2k UqMKTQ2cSGiQFn9iHNpYevBxefI3cA2X183h/i5uXyRrmF/cxFNmQCSDc2uj7gpLe6OQbs eYUDs3KSCw3lEOpGPwEMlYBjc419h7F9ub2t1yJncRo1/J/NgfbSAhjcQ0id0Q== References: <87sfeoksuk.fsf@mailbox.org> <83wn3zej3i.fsf@gnu.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1677778128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DtEiYG9S9D5IyNsFdcoLZTFhJf3ekH4/EF0Gwkcs6og=; b=Zg5BlF7vPx9c0OhFn7PlDQ2Wtyr6sat9Sjb0sVR5IAXQZcF2PMvIl2CUEHblHC0GIIi4TB W09e1K6oZSSlG7xplfnd6ZVUUoutYcorHGt1EaDjAshrG/18Kw+v4jJKJ4hnYZPkfhYIyI kOCA4fow4fdFPgkmU59VPCXyL/acEkw+Qh3wDmJqs5hL9RdtRMAau7WuH1o6AkTmAAymaU CoFwutDVxv0OUC68e52Ul7hF3r0Z3fXhB29daaC45Y5T4EbE0iub3ZvgDu/N+N0pHSRVTX Ok0O0PyE73FE6M3cYIJuvvmIQwS5Gz2eAKNn6jreQS/q9JEHA7fPx4OIUI9Fbw== From: Antero Mejr Date: Thu, 02 Mar 2023 17:09:51 +0000 In-reply-to: <83wn3zej3i.fsf@gnu.org> Message-ID: <87edq7njuh.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-META: 3qc1xmfmxfjbpoabiq8id9yr1511d8eq X-MBO-RS-ID: f57b41bb80e1e0dd5b7 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v2-0001-Add-safe-local-variable-directories-variable.patch >From fa06d54fa49e4da536522e798f8c150d65bccf23 Mon Sep 17 00:00:00 2001 From: Antero Mejr Date: Wed, 1 Mar 2023 21:59:57 +0000 Subject: [PATCH v2] Add safe-local-variable-directories variable. This variable can be set to automatically load risky dir-local variables from a list of trusted directories. * lisp/emacs-lisp/files.el (safe-local-variable-directories, hack-local-variables-filter, hack-local-variables-confirm): New variable and associated logic. * test/lisp/files-tests.el (files-tests-safe-local-variable-directories): Add tests for same. * doc/lispref/variables.texi (File Local Variables): Add documentation for same. * etc/NEWS (Lisp Changes in Emacs 30.1): Add news entry for same. --- doc/lispref/variables.texi | 7 +++++++ etc/NEWS | 5 +++++ lisp/files.el | 27 ++++++++++++++++++++++----- test/lisp/files-tests.el | 21 +++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 5584cbce9a6..93243dcb3c0 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1974,6 +1974,13 @@ File Local Variables symbols. @end defvar +@defvar safe-local-variable-directories +This is a list of directories where local variables are always enabled. +Directory-local variables loaded from these directories, such as the +variables in @file{.dir-locals.el}, will be enabled even if they are +risky. +@end defvar + @defun hack-local-variables &optional handle-mode This function parses, and binds or evaluates as appropriate, any local variables specified by the contents of the current buffer. The variable diff --git a/etc/NEWS b/etc/NEWS index 31fb22fc1e2..249dcb92889 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -238,6 +238,11 @@ hooks named after the feature name, like 'esh-mode-unload-hook'. * Lisp Changes in Emacs 30.1 ++++ +** New variable 'safe-local-variable-directories'. +This variable is used to to permanently trust directories containing +risky directory-local variables. + ** Functions and variables to transpose sexps +++ diff --git a/lisp/files.el b/lisp/files.el index 387a3b5dc66..a7aea449e09 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -681,7 +681,8 @@ enable-local-variables always obeys file local variable specifications and the -*- line, and ignores this variable. -Also see the `permanently-enabled-local-variables' variable." +Also see the `permanently-enabled-local-variables' and +`safe-local-variable-directories' variables." :risky t :type '(choice (const :tag "Query Unsafe" t) (const :tag "Safe Only" :safe) @@ -3692,6 +3693,15 @@ permanently-enabled-local-variables "A list of file-local variables that are always enabled. This overrides any `enable-local-variables' setting.") +(defcustom safe-local-variable-directories '() + "A list of directories where local variables are always enabled. +Directory-local variables loaded from these directories, such as the +variables in .dir-locals.el, will be enabled even if they are risky." + :version "30.1" + :type '(repeat string) + :risky t + :group 'find-file) + (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name) "Get confirmation before setting up local variable values. ALL-VARS is the list of all variables to be set up. @@ -3730,7 +3740,9 @@ hack-local-variables-confirm ! -- to apply the local variables list, and permanently mark these values (*) as safe (in the future, they will be set automatically.) i -- to ignore the local variables list, and permanently mark these - values (*) as ignored\n\n") + values (*) as ignored ++ -- to apply the local variables list, and permanently trust all + directory-local variables in this directory\n\n") (insert "\n\n")) (dolist (elt all-vars) (cond ((member elt unsafe-vars) @@ -3754,7 +3766,7 @@ hack-local-variables-confirm (pop-to-buffer buf '(display-buffer--maybe-at-bottom)) (let* ((exit-chars '(?y ?n ?\s)) (prompt (format "Please type %s%s: " - (if offer-save "y, n, ! or i" "y or n") + (if offer-save "y, n, !, i, or +" "y or n") (if (< (line-number-at-pos (point-max)) (window-body-height)) "" @@ -3762,8 +3774,12 @@ hack-local-variables-confirm char) (when offer-save (push ?i exit-chars) - (push ?! exit-chars)) + (push ?! exit-chars) + (push ?+ exit-chars)) (setq char (read-char-choice prompt exit-chars)) + (when (and offer-save (= char ?+)) + (customize-push-and-save 'safe-local-variable-directories + (list dir-name))) (when (and offer-save (or (= char ?!) (= char ?i)) unsafe-vars) @@ -3772,7 +3788,7 @@ hack-local-variables-confirm 'safe-local-variable-values 'ignored-local-variable-values) unsafe-vars)) - (prog1 (memq char '(?! ?\s ?y)) + (prog1 (memq char '(?! ?\s ?y ?+)) (quit-window t))))))) (defconst hack-local-variable-regexp @@ -3904,6 +3920,7 @@ hack-local-variables-filter (null unsafe-vars) (null risky-vars)) (memq enable-local-variables '(:all :safe)) + (member dir-name safe-local-variable-directories) (hack-local-variables-confirm all-vars unsafe-vars risky-vars dir-name)) (dolist (elt all-vars) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index aadb60e1de7..af74a8b1ecf 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -166,6 +166,27 @@ files-tests-permanent-local-variables (hack-local-variables) (should (eq lexical-binding nil))))) +(ert-deftest files-tests-safe-local-variable-directories () + ;; safe-local-variable-directories should be risky, + ;; so use it as an arbitrary risky variable. + (let ((test-alist '((safe-local-variable-directories . "some_val"))) + (fakedir "test1/test2") + (enable-local-eval t)) + (with-temp-buffer + (setq safe-local-variable-directories (list fakedir)) + (hack-local-variables-filter test-alist fakedir) + (should (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq safe-local-variable-directories (list fakedir)) + (setq noninteractive t) + (hack-local-variables-filter test-alist "wrong") + (should-not (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq safe-local-variable-directories '()) + (setq noninteractive t) + (hack-local-variables-filter test-alist fakedir) + (should-not (equal file-local-variables-alist test-alist))))) + (defvar files-test-bug-18141-file (ert-resource-file "files-bug18141.el.gz") "Test file for bug#18141.") -- 2.38.1 --=-=-= Content-Type: text/plain Eli Zaretskii writes: > This should explicitly allude to the '.dir-locals.el' files in those > directories, since otherwise talking about "directories that contain > variables" could be confusing. Fixed in v2. > I also suggest to rename the variable to something like > 'permanently-safe-local-variable-directories', or maybe just > 'safe-local-variable-directories' which IMO should express the purpose > better. I like 'safe-local-variable-directories', updated to use that. > We quote `like this' in doc strings, to produce links in the *Help* > buffers. Fixed. > The first line of a doc string should be a single complete sentence. > (This is because the various apropos commands show only the first line > of the doc string.) Fixed. > "permanently trust name" sounds confusing (what is "name"?). How > about this variant: > > + -- to apply the local variables list, and permanently trust > all directory-local variables in this directory "name" is a variable that gets expanded to the directory name, but it's redundant since it's already listed at the top. Updated to use your variant. > Bother: AFAIU here we modify the user's custom file without asking for > an explicit permission. Should we ask for permission? IMO they give sufficient permission when the use the "+" option. > Last, but not least: this change is larger than what we can accept > without you assigning to FSF the copyright for your changes, and I > don't see any copyright assignment in your name on file. Would you be > willing to do the legal paperwork for such an assignment? If yes, I > will send you the form to start the paperwork rolling; when it is > completed, we can install your changes. I sent the request-assign.future doc to the FSF assignment email earlier today, feel free to send me paperwork and I will fill it out. Thank you for the review. --=-=-=-- From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Mar 2023 18:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: antero@mailbox.org, 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.1677780272976 (code B ref 61901); Thu, 02 Mar 2023 18:05:01 +0000 Received: (at 61901) by debbugs.gnu.org; 2 Mar 2023 18:04:32 +0000 Received: from localhost ([127.0.0.1]:58343 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXnI7-0000Fe-Pi for submit@debbugs.gnu.org; Thu, 02 Mar 2023 13:04:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXnI5-0000FO-OE for 61901@debbugs.gnu.org; Thu, 02 Mar 2023 13:04:30 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXnI0-0004X0-1L; Thu, 02 Mar 2023 13:04:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=kauOgM43ZUberwWG3hPqVgZxvD8m6OL5ng2+I+gQGSA=; b=sVqnYgro7StJ zT+BnrJo663PsSw36L+RSSSeJwGxk3CKkfpeD2HdpMuLDgfdjIw5HfrlHAW1d+vNA3VQEUCxVDbvr 2vuNtFTsPVZvIvUvSLsvDyzKPgX8Tlf/3NdFH0fYFUqMMDcMYB32XI/86xOcWNHKP1zfPX3jfahBz SqkVfjhLlkcbwGJdzELkNemnhcW4wcjBrDCjXnn6OmiqX3PVDrGALOrgl00e0pT9WiiDNcPIKyDIc 6G9/htse08MIDzJKZPaQvW6X34S8WN9L521OHeR/1IQFOAMgi50B+mZDdUmNpcgBSjcdm7nWSV2hy 3T0O4BZSJ8cJBKebx9eJjQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXnHz-0008Cz-FH; Thu, 02 Mar 2023 13:04:23 -0500 Date: Thu, 02 Mar 2023 20:04:12 +0200 Message-Id: <83sfenc9nn.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87edq7njuh.fsf@mailbox.org> (message from Antero Mejr on Thu, 02 Mar 2023 17:09:51 +0000) References: <87sfeoksuk.fsf@mailbox.org> <83wn3zej3i.fsf@gnu.org> <87edq7njuh.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Antero Mejr > Cc: Antero Mejr , 61901@debbugs.gnu.org > Date: Thu, 02 Mar 2023 17:09:51 +0000 > > I sent the request-assign.future doc to the FSF assignment email earlier > today, feel free to send me paperwork and I will fill it out. That should be enough. If they don't respond within two weeks, ping them and CC me. Thanks. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Mar 2023 18:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.16788196151745 (code B ref 61901); Tue, 14 Mar 2023 18:47:02 +0000 Received: (at 61901) by debbugs.gnu.org; 14 Mar 2023 18:46:55 +0000 Received: from localhost ([127.0.0.1]:38440 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pc9fi-0000S5-KB for submit@debbugs.gnu.org; Tue, 14 Mar 2023 14:46:54 -0400 Received: from mout-p-102.mailbox.org ([80.241.56.152]:55262) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pc9fh-0000Rs-7S for 61901@debbugs.gnu.org; Tue, 14 Mar 2023 14:46:53 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4PbjDP2PXXz9skB; Tue, 14 Mar 2023 19:46:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1678819605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9MPnEJa8T4bqHUbhNuZg+ZvisPME9QaQpJSvM5T510s=; b=iBqmdC5bW5LrK4tb0xJ0WGIpni8Z2uoMSPyVxgFSTNJAowNSF1Ni02eLtpm5ad9TeRJNm2 JhyzK+5tUJicoQc4u1Fm5yV97GqiXXpPC1YSvc1sEDaDPaxCUus00oszskgdQk1kfnJh76 Sh6ErCA0Vfa+H6XqJL4HeCjTOWraLeli8xrVb7Qiygh7HFEJ6X8yphNitHNh69W6yZXVzt r3XhznZ0EqUVeYs9Bp2GWnQtcyqtJ0IwHcymNok3LsHgoGQCKfdXCOk65Azr8f9tT16Rgt ntZn/7YzwpLz9IrRw7cCoKhuc10s5PebHinE+CJhu5IoF4rHM2hGx45sDU0H3Q== From: Antero Mejr In-Reply-To: <83sfenc9nn.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 02 Mar 2023 20:04:12 +0200") References: <87sfeoksuk.fsf@mailbox.org> <83wn3zej3i.fsf@gnu.org> <87edq7njuh.fsf@mailbox.org> <83sfenc9nn.fsf@gnu.org> Date: Tue, 14 Mar 2023 18:46:24 +0000 Message-ID: <871qlrxjb3.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-ID: 72cba13cf7d7362ad80 X-MBO-RS-META: mokb84jhequudus11mc3oftg41td6ex6 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Eli Zaretskii writes: >> I sent the request-assign.future doc to the FSF assignment email earlier >> today, feel free to send me paperwork and I will fill it out. > > That should be enough. If they don't respond within two weeks, ping > them and CC me. I signed and returned the full copyright assignment paperwork last week, so I assume that my copyright assignment is on file now. Let me know if this patch needs a v3 or if there is anything else before it can be applied, thanks. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Mar 2023 19:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.16788232947992 (code B ref 61901); Tue, 14 Mar 2023 19:49:01 +0000 Received: (at 61901) by debbugs.gnu.org; 14 Mar 2023 19:48:14 +0000 Received: from localhost ([127.0.0.1]:38520 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcAd4-00024q-Jr for submit@debbugs.gnu.org; Tue, 14 Mar 2023 15:48:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcAd2-000243-QC for 61901@debbugs.gnu.org; Tue, 14 Mar 2023 15:48:13 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcAcw-0008NS-BZ; Tue, 14 Mar 2023 15:48:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=OS9G6p6Jo32REhdG0iEYQMKMJgwJCcnYYVYRsCfVck0=; b=KyN5Jar9+3E9 BTS6HZseQ5CfO2nh8SLbOqh7Dy7oXrQ72z5N1M6QC4TB1MxYbAoFlVjOMnNmacQ/3KPAMElRcKLEp PnwgCettPr6LrC4FeUTqT2+9duYHS909GNGfsYd5FrPVV+Ut133k+Rjwa3PqgDYasU1TQXgwuWeuO MgIz/rX7/LjnF39x0O9vbN5F0qMjibDtOE+DDJ3UFs1XpqFYIAgkFyvQumes9zLMJv+gcfYOYZWkP ZQ1R4xgiB1PMmiagoTvGafVy8udAMrtTDoJLZ5b/LcETd9HoVOZwl3IBXkDxXjiaJanlWe9Jw9rJS buO2/1hB0C6ka7Q1O7B8pw==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcAcv-0005w4-Lt; Tue, 14 Mar 2023 15:48:06 -0400 Date: Tue, 14 Mar 2023 21:48:00 +0200 Message-Id: <838rfzru6n.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <871qlrxjb3.fsf@mailbox.org> (message from Antero Mejr on Tue, 14 Mar 2023 18:46:24 +0000) References: <87sfeoksuk.fsf@mailbox.org> <83wn3zej3i.fsf@gnu.org> <87edq7njuh.fsf@mailbox.org> <83sfenc9nn.fsf@gnu.org> <871qlrxjb3.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Antero Mejr > Cc: 61901@debbugs.gnu.org > Date: Tue, 14 Mar 2023 18:46:24 +0000 > > Eli Zaretskii writes: > >> I sent the request-assign.future doc to the FSF assignment email earlier > >> today, feel free to send me paperwork and I will fill it out. > > > > That should be enough. If they don't respond within two weeks, ping > > them and CC me. > > I signed and returned the full copyright assignment paperwork last week, > so I assume that my copyright assignment is on file now. It isn't, not yet. You should receive another email with the assignment counter-signed by the FSF, and then it will be added to the DB. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. References: <87sfeoksuk.fsf@mailbox.org> In-Reply-To: <87sfeoksuk.fsf@mailbox.org> Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Apr 2023 16:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168244082415667 (code B ref 61901); Tue, 25 Apr 2023 16:41:01 +0000 Received: (at 61901) by debbugs.gnu.org; 25 Apr 2023 16:40:24 +0000 Received: from localhost ([127.0.0.1]:53449 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prLiK-00044c-70 for submit@debbugs.gnu.org; Tue, 25 Apr 2023 12:40:24 -0400 Received: from mout-p-201.mailbox.org ([80.241.56.171]:33308) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prLiE-00044I-RL for 61901@debbugs.gnu.org; Tue, 25 Apr 2023 12:40:22 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Q5SQy6vBtz9sWC for <61901@debbugs.gnu.org>; Tue, 25 Apr 2023 18:40:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1682440810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=55vAvOHUPGvFKmO4dXjNmefVj+PNrn5jVDm5o6p27aI=; b=rTOk6i6R23IdUiB5bN+X+iWymwTVf7Ix6UzZ6iwBy2FbzkaNNqikYaVb409EaNzbVSy5uv 7ojMJYTU2KpayNFcD3hDRCV5ShoCTm41wF+VE93BARJVZaBSWpsv3L6bprwWpnXnqNct0m RHEl/6mChceLVyzZxQk1pRAFtOF09dHueBnySh6taRNvYwFz3PDQoqoAZpKUekZkC2aQMp hBu8JRBMRazpiMLqT7mTqZLVf3UxjOzSga2FYx1TL75p2soD5K5gQ4SRiTiKCpvE/im9gI g8xzOTdSUSqKrxjMbGKHGH5GjT4QnAYk5YeDSE4tws5oiKeyIhPXB8fjomu2LQ== From: Antero Mejr Date: Tue, 25 Apr 2023 16:40:07 +0000 Message-ID: <87354nlxug.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-ID: 02986b6babcc8640436 X-MBO-RS-META: 5ryudexbbhwgrc74r5h3ebd1w4s19zmn X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Updated safe-local-variable-directories patch onto master and added bug number to commit message. Also should I use git --reroll-count to make v2 patches, v3, etc? If so then I included another patch to gitignore rerolled patches, otherwise please disregard it. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v3-0001-Add-safe-local-variable-directories-variable.patch >From 21506c01f72b10fb69ede16333e4970c0c402851 Mon Sep 17 00:00:00 2001 From: Antero Mejr Date: Tue, 25 Apr 2023 15:30:16 +0000 Subject: [PATCH v3] Add safe-local-variable-directories variable. This variable can be set to automatically load risky dir-local variables from a list of trusted directories. * lisp/emacs-lisp/files.el (safe-local-variable-directories, hack-local-variables-filter, hack-local-variables-confirm): New variable and associated logic. * test/lisp/files-tests.el (files-tests-safe-local-variable-directories): Add tests for same. * doc/lispref/variables.texi (File Local Variables): Add documentation for same. * etc/NEWS (Lisp Changes in Emacs 30.1): Add news entry for same. (Bug#61901) --- doc/lispref/variables.texi | 7 +++++++ etc/NEWS | 5 +++++ lisp/files.el | 27 ++++++++++++++++++++++----- test/lisp/files-tests.el | 21 +++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index eadb5c36de6..7df41a7c997 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1977,6 +1977,13 @@ this can be controlled by using this variable, which is a list of symbols. @end defvar +@defvar safe-local-variable-directories +This is a list of directories where local variables are always enabled. +Directory-local variables loaded from these directories, such as the +variables in @file{.dir-locals.el}, will be enabled even if they are +risky. +@end defvar + @defun hack-local-variables &optional handle-mode This function parses, and binds or evaluates as appropriate, any local variables specified by the contents of the current buffer. The variable diff --git a/etc/NEWS b/etc/NEWS index d39343b8bd4..4eb3ab27139 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -375,6 +375,11 @@ hooks named after the feature name, like 'esh-mode-unload-hook'. * Lisp Changes in Emacs 30.1 ++++ +** New variable 'safe-local-variable-directories'. +This variable is used to to permanently trust directories containing +risky directory-local variables. + ** New variable 'inhibit-auto-fill' to temporarily prevent auto-fill. ** Functions and variables to transpose sexps diff --git a/lisp/files.el b/lisp/files.el index c6f53e5eaf8..3152fc61d9d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -681,7 +681,8 @@ The command \\[normal-mode], when used interactively, always obeys file local variable specifications and the -*- line, and ignores this variable. -Also see the `permanently-enabled-local-variables' variable." +Also see the `permanently-enabled-local-variables' and +`safe-local-variable-directories' variables." :risky t :type '(choice (const :tag "Query Unsafe" t) (const :tag "Safe Only" :safe) @@ -3696,6 +3697,15 @@ variable to set.") "A list of file-local variables that are always enabled. This overrides any `enable-local-variables' setting.") +(defcustom safe-local-variable-directories '() + "A list of directories where local variables are always enabled. +Directory-local variables loaded from these directories, such as the +variables in .dir-locals.el, will be enabled even if they are risky." + :version "30.1" + :type '(repeat string) + :risky t + :group 'find-file) + (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name) "Get confirmation before setting up local variable values. ALL-VARS is the list of all variables to be set up. @@ -3734,7 +3744,9 @@ n -- to ignore the local variables list.") ! -- to apply the local variables list, and permanently mark these values (*) as safe (in the future, they will be set automatically.) i -- to ignore the local variables list, and permanently mark these - values (*) as ignored\n\n") + values (*) as ignored ++ -- to apply the local variables list, and permanently trust all + directory-local variables in this directory\n\n") (insert "\n\n")) (dolist (elt all-vars) (cond ((member elt unsafe-vars) @@ -3758,7 +3770,7 @@ i -- to ignore the local variables list, and permanently mark these (pop-to-buffer buf '(display-buffer--maybe-at-bottom)) (let* ((exit-chars '(?y ?n ?\s)) (prompt (format "Please type %s%s: " - (if offer-save "y, n, ! or i" "y or n") + (if offer-save "y, n, !, i, or +" "y or n") (if (< (line-number-at-pos (point-max)) (window-body-height)) "" @@ -3766,8 +3778,12 @@ i -- to ignore the local variables list, and permanently mark these char) (when offer-save (push ?i exit-chars) - (push ?! exit-chars)) + (push ?! exit-chars) + (push ?+ exit-chars)) (setq char (read-char-choice prompt exit-chars)) + (when (and offer-save (= char ?+)) + (customize-push-and-save 'safe-local-variable-directories + (list dir-name))) (when (and offer-save (or (= char ?!) (= char ?i)) unsafe-vars) @@ -3776,7 +3792,7 @@ i -- to ignore the local variables list, and permanently mark these 'safe-local-variable-values 'ignored-local-variable-values) unsafe-vars)) - (prog1 (memq char '(?! ?\s ?y)) + (prog1 (memq char '(?! ?\s ?y ?+)) (quit-window t))))))) (defconst hack-local-variable-regexp @@ -3908,6 +3924,7 @@ 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) (hack-local-variables-confirm all-vars unsafe-vars risky-vars dir-name)) (dolist (elt all-vars) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index aadb60e1de7..af74a8b1ecf 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -166,6 +166,27 @@ form.") (hack-local-variables) (should (eq lexical-binding nil))))) +(ert-deftest files-tests-safe-local-variable-directories () + ;; safe-local-variable-directories should be risky, + ;; so use it as an arbitrary risky variable. + (let ((test-alist '((safe-local-variable-directories . "some_val"))) + (fakedir "test1/test2") + (enable-local-eval t)) + (with-temp-buffer + (setq safe-local-variable-directories (list fakedir)) + (hack-local-variables-filter test-alist fakedir) + (should (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq safe-local-variable-directories (list fakedir)) + (setq noninteractive t) + (hack-local-variables-filter test-alist "wrong") + (should-not (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq safe-local-variable-directories '()) + (setq noninteractive t) + (hack-local-variables-filter test-alist fakedir) + (should-not (equal file-local-variables-alist test-alist))))) + (defvar files-test-bug-18141-file (ert-resource-file "files-bug18141.el.gz") "Test file for bug#18141.") -- 2.39.2 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Ignore-rerolled-patches.patch >From e847ad3f782304f210c318502da031d8a810834f Mon Sep 17 00:00:00 2001 From: Antero Mejr Date: Tue, 25 Apr 2023 15:33:18 +0000 Subject: [PATCH] Ignore rerolled patches. * .gitignore (Version control and locks): Ignore .patch files that start with "v" and a number 0-99. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b09a0c030b3..139eb49ba41 100644 --- a/.gitignore +++ b/.gitignore @@ -283,6 +283,8 @@ gnustmp* \#*\# ChangeLog [0-9]*.patch +v[0-9]-[0-9]*.patch +v[0-9][0-9]-[0-9]*.patch [0-9]*.txt /vc-dwim-log-* -- 2.39.2 --=-=-=-- From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Apr 2023 17:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168244341720654 (code B ref 61901); Tue, 25 Apr 2023 17:24:01 +0000 Received: (at 61901) by debbugs.gnu.org; 25 Apr 2023 17:23:37 +0000 Received: from localhost ([127.0.0.1]:53494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prMO8-0005N3-OL for submit@debbugs.gnu.org; Tue, 25 Apr 2023 13:23:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prMO5-0005Mo-G3 for 61901@debbugs.gnu.org; Tue, 25 Apr 2023 13:23:35 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prMNz-0001vF-KA; Tue, 25 Apr 2023 13:23:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=jVwGayWYf00/u07dNBpsRr1RaGbwKybIpu+Txy43HKg=; b=PQikz9TtHpOg hHcBelqF5hjAhyfk1IrwW5/Y2AwQogirL0yyLq3xDGliOPI8r/hTURd3+zzP6dtdhi6v+aFzpH5MM iJRQHmmY2VvG1W9o+EwEkblZB8ctRrv/hYhLa+Q5DZIrY5iXNYrtzcIZR6GpDT8GkLxS0Ns7hfCRA 8o/QZSwu6xQSCUYBYVf/3ih8fOBid4AZDsUWt/QqgNbMPdpmdKqBu54yf3I+6pFn0vfH9X15BxrUM xQQMlwrPIVfLy6944+B3Xeq72M9xvrNE3yo9C4UMyhfJ1F1SCF0phH+jYotFserHKCd00Rq4r6onv 6Vmn714y4If9wnCd9jUvKA==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prMNy-0007Gk-J4; Tue, 25 Apr 2023 13:23:27 -0400 Date: Tue, 25 Apr 2023 20:23:53 +0300 Message-Id: <83jzxzvpsm.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87354nlxug.fsf@mailbox.org> (bug-gnu-emacs@gnu.org) References: <87sfeoksuk.fsf@mailbox.org> <87354nlxug.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Tue, 25 Apr 2023 16:40:07 +0000 > From: Antero Mejr via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > Updated safe-local-variable-directories patch onto master and added bug > number to commit message. Thanks, see some comments below. > Also should I use git --reroll-count to make v2 patches, v3, etc? You don't have to. The version part is removed by "git am" anyway, and it is not important for patch review here. > --- a/doc/lispref/variables.texi > +++ b/doc/lispref/variables.texi > @@ -1977,6 +1977,13 @@ this can be controlled by using this variable, which is a list of > symbols. > @end defvar > > +@defvar safe-local-variable-directories > +This is a list of directories where local variables are always enabled. > +Directory-local variables loaded from these directories, such as the > +variables in @file{.dir-locals.el}, will be enabled even if they are > +risky. > +@end defvar This variable should also be documented in the Emacs user manual, not only in the ELisp Reference manual -- it's a user option, and a very important one at that. > ++++ > +** New variable 'safe-local-variable-directories'. > +This variable is used to to permanently trust directories containing > +risky directory-local variables. I would rephrase: This variable names directories in which Emacs will treat all directory-local variables as safe. > ALL-VARS is the list of all variables to be set up. > @@ -3734,7 +3744,9 @@ n -- to ignore the local variables list.") > ! -- to apply the local variables list, and permanently mark these > values (*) as safe (in the future, they will be set automatically.) > i -- to ignore the local variables list, and permanently mark these > - values (*) as ignored\n\n") > + values (*) as ignored > ++ -- to apply the local variables list, and permanently trust all > + directory-local variables in this directory\n\n") I would remove the "permanently" part, it would just confuse here. > @@ -3908,6 +3924,7 @@ 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) If you use 'member' for this test, then (a) the documentation of safe-local-variable-directories should explicitly say that the directories in the list must be in full absolute form, and (b) we should consider the various issues with file names that are not 'equal' as strings, but still name the same directory, such as letter-case differences on case-insensitive filesystems. And what about equality of "foo/" "and "foo"? Also, is 'dir-name' above guaranteed to be a fully-expanded absolute file name? > +(ert-deftest files-tests-safe-local-variable-directories () > + ;; safe-local-variable-directories should be risky, > + ;; so use it as an arbitrary risky variable. > + (let ((test-alist '((safe-local-variable-directories . "some_val"))) > + (fakedir "test1/test2") > + (enable-local-eval t)) > + (with-temp-buffer > + (setq safe-local-variable-directories (list fakedir)) The test should use absolute directory names for directories you put into safe-local-variable-directories. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. References: <87sfeoksuk.fsf@mailbox.org> Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 May 2023 21:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: eliz@gnu.org Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168366781132396 (code B ref 61901); Tue, 09 May 2023 21:31:01 +0000 Received: (at 61901) by debbugs.gnu.org; 9 May 2023 21:30:11 +0000 Received: from localhost ([127.0.0.1]:44640 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pwUuQ-0008QS-3h for submit@debbugs.gnu.org; Tue, 09 May 2023 17:30:10 -0400 Received: from mout-p-202.mailbox.org ([80.241.56.172]:48624) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pwUuM-0008OM-9N for 61901@debbugs.gnu.org; Tue, 09 May 2023 17:30:09 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4QGBBt38s3z9sRC; Tue, 9 May 2023 23:29:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1683667798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=IMvHJAQWS3Yc4fcOpTQtCLtlZLeIe5WwBN8qHFTRuKk=; b=ll1+wtk+YqEEz2nugoMSSUvBYyy84YZjwJ0LTcndL2r/4pfiFjj+gB35trQjml+jfR9+GX Ph03ira+Er4vdwqetpQmO98csKzSBv0LwQ7NYPLVHog/Rqe2hjensYIbNEj0UeK5cfjWwd MDQGpW6oiEtDNKoWpzGaQeigbNkP0XKajar30w0NM/hWaXAd4+03SRo8/Ajy4mjkFd7cC1 Zc4z6ApVaCSg8CN0r02DfTevPXh5s/ejPsP59LcbcaD4/1qA+FyvQG9Pf0F2UyG34u6Gm+ /kWQCRy+YHt+8fK7pmwg/42asTFEZpUUog7IBHduhKSzjwWqM7++lbkrJCjS8w== From: Antero Mejr In-Reply-To: 83jzxzvpsm.fsf@gnu.org Date: Tue, 09 May 2023 21:29:54 +0000 Message-ID: <87r0rpi46l.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-META: m6ufndr1yw1xk3ndcnm8y1zbkfij1sg6 X-MBO-RS-ID: 6b07dbd311492477f13 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain >> +@defvar safe-local-variable-directories >> +This is a list of directories where local variables are always enabled. >> +Directory-local variables loaded from these directories, such as the >> +variables in @file{.dir-locals.el}, will be enabled even if they are >> +risky. >> +@end defvar > >This variable should also be documented in the Emacs user manual, not >only in the ELisp Reference manual -- it's a user option, and a very >important one at that. Added to the manual in custom.texi "Safe File Variables" subsection. >> ++++ >> +** New variable 'safe-local-variable-directories'. >> +This variable is used to to permanently trust directories containing >> +risky directory-local variables. > >I would rephrase: > > This variable names directories in which Emacs will treat all > directory-local variables as safe. Fixed in attached patch. >> ALL-VARS is the list of all variables to be set up. >> @@ -3734,7 +3744,9 @@ n -- to ignore the local variables list.") >> ! -- to apply the local variables list, and permanently mark these >> values (*) as safe (in the future, they will be set automatically.) >> i -- to ignore the local variables list, and permanently mark these >> - values (*) as ignored\n\n") >> + values (*) as ignored >> ++ -- to apply the local variables list, and permanently trust all >> + directory-local variables in this directory\n\n") > >I would remove the "permanently" part, it would just confuse here. Fixed. >> @@ -3908,6 +3924,7 @@ 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) > >If you use 'member' for this test, then (a) the documentation of >safe-local-variable-directories should explicitly say that the >directories in the list must be in full absolute form, and (b) we >should consider the various issues with file names that are not >'equal' as strings, but still name the same directory, such as >letter-case differences on case-insensitive filesystems. And what >about equality of "foo/" "and "foo"? Clarified the documentation. The directory path requires a trailing separator, and is case-sensitive regardless of the filesystem (tested on vFAT). >Also, is 'dir-name' above guaranteed to be a fully-expanded absolute >file name? Yes. For TRAMP connections it's a string with text properties, but it's the same equality-wise. #("/ssh:user:/home/user/src/" 5 6 (tramp-default t)) >> +(ert-deftest files-tests-safe-local-variable-directories () >> + ;; safe-local-variable-directories should be risky, >> + ;; so use it as an arbitrary risky variable. >> + (let ((test-alist '((safe-local-variable-directories . "some_val"))) >> + (fakedir "test1/test2") >> + (enable-local-eval t)) >> + (with-temp-buffer >> + (setq safe-local-variable-directories (list fakedir)) > >The test should use absolute directory names for directories you put >into safe-local-variable-directories. Fixed. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-safe-local-variable-directories-variable.patch >From 4ecb9ebc01c856f896ed2fee110b491209e23c4e Mon Sep 17 00:00:00 2001 From: Antero Mejr Date: Tue, 9 May 2023 20:51:14 +0000 Subject: [PATCH] Add safe-local-variable-directories variable. This variable can be set to automatically load risky dir-local variables from a list of trusted directories. * lisp/emacs-lisp/files.el (safe-local-variable-directories, hack-local-variables-filter, hack-local-variables-confirm): New variable and associated logic. * test/lisp/files-tests.el (files-tests-safe-local-variable-directories): Add tests for same. * doc/emacs/custom.texi (Safe File Variables): Add documentation for same. * doc/lispref/variables.texi (File Local Variables): Add documentation for same. * etc/NEWS (Lisp Changes in Emacs 30.1): Add news entry for same. (Bug#61901) --- doc/emacs/custom.texi | 22 ++++++++++++++++++++++ doc/lispref/variables.texi | 12 ++++++++++++ etc/NEWS | 5 +++++ lisp/files.el | 34 +++++++++++++++++++++++++++++----- test/lisp/files-tests.el | 21 +++++++++++++++++++++ 5 files changed, 89 insertions(+), 5 deletions(-) diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index 87290734cc9..2ddd39be31f 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -1328,6 +1328,13 @@ pairs in the file, by typing @kbd{i} at the confirmation prompt -- these pairs will thereafter be ignored in this file and in all other files. + For directory-local variable/value pairs +(@pxref{Directory Variables}), typing @kbd{+} at the confirmation +prompt will set all the variable/value pairs, and recognize all +variables in that directory as safe in the future. This option should +only be used for directories whose contents you trust. The @kbd{+} +confirmation prompt option is not available for file-local variables. + @vindex safe-local-variable-values @vindex ignored-local-variable-values @cindex risky variable @@ -1344,6 +1351,21 @@ record safe values for risky variables, do it directly by customizing Similarly, if you want to record values of risky variables that should be permanently ignored, customize @code{ignored-local-variable-values}. +@vindex safe-local-variable-directories + Sometimes it is helpful to always trust risky variables in a certain +directory, and skip the confirmation prompt when directory-local +variables are loaded there. When @kbd{+} is pressed at the risky +variable confirmation prompt, the directory in question is added to +the @samp{safe-local-variable-directories} variable, and risky +directory-local variables there will be loaded without prompting in +the future. If customizing @samp{safe-local-variable-directories} +manually, the directories in this list must be fully-expanded absolute +paths that end in a directory separator character. Directory paths +may be remote directory paths (@pxref{Remote Files}), if the +@code{enable-remote-dir-locals} variable is set to @code{t}. +Directory paths in this list are case-sensitive, even if the +filesystem is not. + @vindex enable-local-variables The variable @code{enable-local-variables} allows you to change the way Emacs processes local variables. Its default value is @code{t}, diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index eadb5c36de6..52a94db3703 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1977,6 +1977,18 @@ this can be controlled by using this variable, which is a list of symbols. @end defvar +@defvar safe-local-variable-directories +This is a list of directories where local variables are always +enabled. Directory-local variables loaded from these directories, +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 paths that end in a directory separator +character. They may also be remote directory paths if the +@code{enable-remote-dir-locals} variable is set to @code{t}. +Directory paths in this list are case-sensitive, even if the +filesystem is not. +@end defvar + @defun hack-local-variables &optional handle-mode This function parses, and binds or evaluates as appropriate, any local variables specified by the contents of the current buffer. The variable diff --git a/etc/NEWS b/etc/NEWS index 3c71e52fff4..3bef9d2ed2a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -380,6 +380,11 @@ hooks named after the feature name, like 'esh-mode-unload-hook'. * Lisp Changes in Emacs 30.1 ++++ +** New variable 'safe-local-variable-directories'. +This variable names directories in which Emacs will treat all +directory-local variables as safe. + ** New variable 'inhibit-auto-fill' to temporarily prevent auto-fill. ** Functions and variables to transpose sexps diff --git a/lisp/files.el b/lisp/files.el index c6f53e5eaf8..aa01e638c98 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -681,7 +681,8 @@ The command \\[normal-mode], when used interactively, always obeys file local variable specifications and the -*- line, and ignores this variable. -Also see the `permanently-enabled-local-variables' variable." +Also see the `permanently-enabled-local-variables' and +`safe-local-variable-directories' variables." :risky t :type '(choice (const :tag "Query Unsafe" t) (const :tag "Safe Only" :safe) @@ -3696,6 +3697,15 @@ variable to set.") "A list of file-local variables that are always enabled. This overrides any `enable-local-variables' setting.") +(defcustom safe-local-variable-directories '() + "A list of directories where local variables are always enabled. +Directory-local variables loaded from these directories, such as the +variables in .dir-locals.el, will be enabled even if they are risky." + :version "30.1" + :type '(repeat string) + :risky t + :group 'find-file) + (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name) "Get confirmation before setting up local variable values. ALL-VARS is the list of all variables to be set up. @@ -3734,7 +3744,11 @@ n -- to ignore the local variables list.") ! -- to apply the local variables list, and permanently mark these values (*) as safe (in the future, they will be set automatically.) i -- to ignore the local variables list, and permanently mark these - values (*) as ignored\n\n") + values (*) as ignored" + (if dir-name " ++ -- to apply the local variables list, and trust all directory-local + variables in this directory\n\n" + "\n\n")) (insert "\n\n")) (dolist (elt all-vars) (cond ((member elt unsafe-vars) @@ -3758,7 +3772,11 @@ i -- to ignore the local variables list, and permanently mark these (pop-to-buffer buf '(display-buffer--maybe-at-bottom)) (let* ((exit-chars '(?y ?n ?\s)) (prompt (format "Please type %s%s: " - (if offer-save "y, n, ! or i" "y or n") + (if offer-save + (if dir-name + "y, n, !, i, +" + "y, n, !, i") + "y or n") (if (< (line-number-at-pos (point-max)) (window-body-height)) "" @@ -3766,8 +3784,13 @@ i -- to ignore the local variables list, and permanently mark these char) (when offer-save (push ?i exit-chars) - (push ?! exit-chars)) + (push ?! exit-chars) + (when dir-name + (push ?+ exit-chars))) (setq char (read-char-choice prompt exit-chars)) + (when (and offer-save dir-name (= char ?+)) + (customize-push-and-save 'safe-local-variable-directories + (list dir-name))) (when (and offer-save (or (= char ?!) (= char ?i)) unsafe-vars) @@ -3776,7 +3799,7 @@ i -- to ignore the local variables list, and permanently mark these 'safe-local-variable-values 'ignored-local-variable-values) unsafe-vars)) - (prog1 (memq char '(?! ?\s ?y)) + (prog1 (memq char '(?! ?\s ?y ?+)) (quit-window t))))))) (defconst hack-local-variable-regexp @@ -3908,6 +3931,7 @@ 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) (hack-local-variables-confirm all-vars unsafe-vars risky-vars dir-name)) (dolist (elt all-vars) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index aadb60e1de7..e87bb3cfa0a 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -166,6 +166,27 @@ form.") (hack-local-variables) (should (eq lexical-binding nil))))) +(ert-deftest files-tests-safe-local-variable-directories () + ;; safe-local-variable-directories should be risky, + ;; so use it as an arbitrary risky variable. + (let ((test-alist '((safe-local-variable-directories . "some_val"))) + (fakedir "/test1/test2/") + (enable-local-eval t)) + (with-temp-buffer + (setq safe-local-variable-directories (list fakedir)) + (hack-local-variables-filter test-alist fakedir) + (should (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq safe-local-variable-directories (list fakedir)) + (setq noninteractive t) + (hack-local-variables-filter test-alist "wrong") + (should-not (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq safe-local-variable-directories '()) + (setq noninteractive t) + (hack-local-variables-filter test-alist fakedir) + (should-not (equal file-local-variables-alist test-alist))))) + (defvar files-test-bug-18141-file (ert-resource-file "files-bug18141.el.gz") "Test file for bug#18141.") -- 2.39.2 --=-=-=-- From unknown Tue Jun 17 22:26:14 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Antero Mejr Subject: bug#61901: closed (Re: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable.) Message-ID: References: <835y8z55w5.fsf@gnu.org> <87sfeoksuk.fsf@mailbox.org> X-Gnu-PR-Message: they-closed 61901 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 61901@debbugs.gnu.org Date: Thu, 11 May 2023 13:55:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1683813302-2954-1" This is a multi-part message in MIME format... ------------=_1683813302-2954-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #61901: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variab= le. which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 61901@debbugs.gnu.org. --=20 61901: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D61901 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1683813302-2954-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 61901-done) by debbugs.gnu.org; 11 May 2023 13:54:55 +0000 Received: from localhost ([127.0.0.1]:50105 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1px6kw-0000lA-Nx for submit@debbugs.gnu.org; Thu, 11 May 2023 09:54:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42724) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1px6kv-0000kv-2O for 61901-done@debbugs.gnu.org; Thu, 11 May 2023 09:54:53 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1px6kp-0000r1-9m; Thu, 11 May 2023 09:54:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=s9KCHZlXdu7mAPJbhsswH7nFz6cql3PFoqyWX/v0rhw=; b=W5rimbgPoVBt MAonUQHCjPBetywuxcbRXBcYNYhBhMz4wMvmOq3ZmhIEMvrS0h8cSriK05E8U7wEUt3En7Mh43mpR ipYkyY7L8YFhxSUaIY/mU+BSfiWD+gsmMAUVbd75riZNzeQxbJxOsutRabNYEfWjGAb6JkJFSn5Ct wgi2qj3yMhn1cErh4WGXrXyJj3fCpxouteM0NTSnPPDF4MqzctZFlee/1ZJ5cF7LCLQs6HNBevWLF A6JOeoUTaLP70FWBAerkqQUklhCMd/pbsEGJ976Ka3UwIMSclGuegXdJlKllk4cNTXXxjhkK7k22C ZEKwpKiKCE3ac9EPCtN7UQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1px6ko-0002ug-Q9; Thu, 11 May 2023 09:54:47 -0400 Date: Thu, 11 May 2023 16:55:54 +0300 Message-Id: <835y8z55w5.fsf@gnu.org> From: Eli Zaretskii To: Antero Mejr In-Reply-To: <87r0rpi46l.fsf@mailbox.org> (message from Antero Mejr on Tue, 09 May 2023 21:29:54 +0000) Subject: Re: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. References: <87r0rpi46l.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 61901-done Cc: 61901-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Antero Mejr > Cc: 61901@debbugs.gnu.org > Date: Tue, 09 May 2023 21:29:54 +0000 > > >> +@defvar safe-local-variable-directories > >> +This is a list of directories where local variables are always enabled. > >> +Directory-local variables loaded from these directories, such as the > >> +variables in @file{.dir-locals.el}, will be enabled even if they are > >> +risky. > >> +@end defvar > > > >This variable should also be documented in the Emacs user manual, not > >only in the ELisp Reference manual -- it's a user option, and a very > >important one at that. > > Added to the manual in custom.texi "Safe File Variables" subsection. > > >> ++++ > >> +** New variable 'safe-local-variable-directories'. > >> +This variable is used to to permanently trust directories containing > >> +risky directory-local variables. > > > >I would rephrase: > > > > This variable names directories in which Emacs will treat all > > directory-local variables as safe. > > Fixed in attached patch. > > >> ALL-VARS is the list of all variables to be set up. > >> @@ -3734,7 +3744,9 @@ n -- to ignore the local variables list.") > >> ! -- to apply the local variables list, and permanently mark these > >> values (*) as safe (in the future, they will be set automatically.) > >> i -- to ignore the local variables list, and permanently mark these > >> - values (*) as ignored\n\n") > >> + values (*) as ignored > >> ++ -- to apply the local variables list, and permanently trust all > >> + directory-local variables in this directory\n\n") > > > >I would remove the "permanently" part, it would just confuse here. > > Fixed. > > >> @@ -3908,6 +3924,7 @@ 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) > > > >If you use 'member' for this test, then (a) the documentation of > >safe-local-variable-directories should explicitly say that the > >directories in the list must be in full absolute form, and (b) we > >should consider the various issues with file names that are not > >'equal' as strings, but still name the same directory, such as > >letter-case differences on case-insensitive filesystems. And what > >about equality of "foo/" "and "foo"? > > Clarified the documentation. The directory path requires a trailing > separator, and is case-sensitive regardless of the filesystem (tested > on vFAT). > > >Also, is 'dir-name' above guaranteed to be a fully-expanded absolute > >file name? > > Yes. For TRAMP connections it's a string with text properties, but it's > the same equality-wise. > > #("/ssh:user:/home/user/src/" 5 6 (tramp-default t)) > > >> +(ert-deftest files-tests-safe-local-variable-directories () > >> + ;; safe-local-variable-directories should be risky, > >> + ;; so use it as an arbitrary risky variable. > >> + (let ((test-alist '((safe-local-variable-directories . "some_val"))) > >> + (fakedir "test1/test2") > >> + (enable-local-eval t)) > >> + (with-temp-buffer > >> + (setq safe-local-variable-directories (list fakedir)) > > > >The test should use absolute directory names for directories you put > >into safe-local-variable-directories. > > Fixed. Thanks, I installed this on the master branch, and I'm therefore closing this bug. Please note some minor changes I made in the documentation parts of the changeset, the most notable one being the use of "path" to allude to file names or directory names: the Gnu Coding Standards frown on that. We use "path" only for lists of directories in the style of PATH environment variable or load-path Lisp variable. Thanks again for working on this feature. ------------=_1683813302-2954-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 1 Mar 2023 22:31:03 +0000 Received: from localhost ([127.0.0.1]:55211 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXUyU-0002rI-CO for submit@debbugs.gnu.org; Wed, 01 Mar 2023 17:31:02 -0500 Received: from lists.gnu.org ([209.51.188.17]:36388) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXUyS-0002r3-Ci for submit@debbugs.gnu.org; Wed, 01 Mar 2023 17:31:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXUyS-0005XM-6I for bug-gnu-emacs@gnu.org; Wed, 01 Mar 2023 17:31:00 -0500 Received: from mout-p-101.mailbox.org ([80.241.56.151]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1pXUyP-00053u-PB for bug-gnu-emacs@gnu.org; Wed, 01 Mar 2023 17:30:59 -0500 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4PRppS4XlDz9sSS for ; Wed, 1 Mar 2023 23:30:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1677709824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=K9lD2zACD9/PmXIuMYcRDKjp/UzoQ9ullRVNcrRxaBk=; b=KJ6xHaHX3BWKFNkaQXocKluzJxhg4OEz+KdbxBAR3yLU6wKVJgzr44ds3GCDHLS/3MtFFx DM0UPhv9uib1JvLfKIxwxlxv/vEIrqXSY1rXMS3ekZzLSTIckhN4c+nupgPRTIwIB2S0G5 fA/86g6audaSpT5Jyc4hSYV86Q190hEmx5nALAqTWfBC5yPQhSn5sMctnZBUYlVaXojVv3 GEA1M+5kVUR/lvTkXncE+hzAV2Ek8oPE2wV8YQDkJ2GmgLpZin5vPgyaOhDMLMfCgPg+E6 2+OLQT1eCr8DfagARXGEmzGNMXJ5yCJETrWmRVNvAi9n2rOQ53m7gzY3r9SHIA== From: Antero Mejr To: bug-gnu-emacs@gnu.org Subject: 30.0.50; [PATCH] Add permanently-enabled-local-variable-dirs variable. Date: Wed, 01 Mar 2023 22:20:33 +0000 Message-ID: <87sfeoksuk.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-META: hrggins9umdge4xsoz6jg36j9y6ogmcj X-MBO-RS-ID: 1c79a36e36ecc3d0473 Received-SPF: pass client-ip=80.241.56.151; envelope-from=antero@mailbox.org; helo=mout-p-101.mailbox.org X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain This patch allows users to trust directories to load dir-local variables from, so they don't have to do something lile this: (defun risky-local-variable-p (sym &optional _ignored) nil) as suggested here: https://emacs.stackexchange.com/questions/10983/remember-permission-to-execute-risky-local-variables It also works over TRAMP if enable-remote-dir-locals is true. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-permanently-enabled-local-variable-dirs-variable.patch >From 93494f5beb4b51d989ea87755c077379458ffb04 Mon Sep 17 00:00:00 2001 From: Antero Mejr Date: Wed, 1 Mar 2023 21:59:57 +0000 Subject: [PATCH] Add permanently-enabled-local-variable-dirs variable. This variable can be set to automatically load risky dir-local variables from a list of trusted directories. * lisp/emacs-lisp/files.el (permanently-enabled-local-variable-dirs, hack-local-variables-filter, hack-local-variables-confirm): New variable and associated logic. * test/lisp/files-tests.el (files-tests-permanently-enabled-local-variable-dirs): Add tests for same. * doc/lispref/variables.texi (File Local Variables): Add documentation for same. * etc/NEWS (Lisp Changes in Emacs 30.1): Add news entry for same. --- doc/lispref/variables.texi | 6 ++++++ etc/NEWS | 5 +++++ lisp/files.el | 27 ++++++++++++++++++++++----- test/lisp/files-tests.el | 22 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 5584cbce9a6..47cfb824dcb 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1974,6 +1974,12 @@ File Local Variables symbols. @end defvar +@defvar permanently-enabled-local-variable-dirs +This is a list of trusted directories that contain local variables. +Local variables in these directories will always be enabled, regardless +of whether they are risky. +@end defvar + @defun hack-local-variables &optional handle-mode This function parses, and binds or evaluates as appropriate, any local variables specified by the contents of the current buffer. The variable diff --git a/etc/NEWS b/etc/NEWS index 31fb22fc1e2..cc5198a903b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -238,6 +238,11 @@ hooks named after the feature name, like 'esh-mode-unload-hook'. * Lisp Changes in Emacs 30.1 ++++ +** New variable 'permanently-enabled-local-variable-dirs'. +This variable is used to to permanently trust directories containing +risky directory-local variables. + ** Functions and variables to transpose sexps +++ diff --git a/lisp/files.el b/lisp/files.el index 387a3b5dc66..bde126375ae 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -681,7 +681,8 @@ enable-local-variables always obeys file local variable specifications and the -*- line, and ignores this variable. -Also see the `permanently-enabled-local-variables' variable." +Also see the `permanently-enabled-local-variables' and +'permanently-enabled-local-variable-dirs' variables." :risky t :type '(choice (const :tag "Query Unsafe" t) (const :tag "Safe Only" :safe) @@ -3692,6 +3693,14 @@ permanently-enabled-local-variables "A list of file-local variables that are always enabled. This overrides any `enable-local-variables' setting.") +(defcustom permanently-enabled-local-variable-dirs '() + "A list of directories that contain local variables that are always +enabled, regardless of whether they are risky." + :version "30.1" + :type '(repeat string) + :risky t + :group 'find-file) + (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name) "Get confirmation before setting up local variable values. ALL-VARS is the list of all variables to be set up. @@ -3730,7 +3739,9 @@ hack-local-variables-confirm ! -- to apply the local variables list, and permanently mark these values (*) as safe (in the future, they will be set automatically.) i -- to ignore the local variables list, and permanently mark these - values (*) as ignored\n\n") + values (*) as ignored ++ -- to apply the local variables list, and permanently trust " + name "\n\n") (insert "\n\n")) (dolist (elt all-vars) (cond ((member elt unsafe-vars) @@ -3754,7 +3765,7 @@ hack-local-variables-confirm (pop-to-buffer buf '(display-buffer--maybe-at-bottom)) (let* ((exit-chars '(?y ?n ?\s)) (prompt (format "Please type %s%s: " - (if offer-save "y, n, ! or i" "y or n") + (if offer-save "y, n, !, i, or +" "y or n") (if (< (line-number-at-pos (point-max)) (window-body-height)) "" @@ -3762,8 +3773,13 @@ hack-local-variables-confirm char) (when offer-save (push ?i exit-chars) - (push ?! exit-chars)) + (push ?! exit-chars) + (push ?+ exit-chars)) (setq char (read-char-choice prompt exit-chars)) + (when (and offer-save (= char ?+)) + (customize-push-and-save + 'permanently-enabled-local-variable-dirs + (list dir-name))) (when (and offer-save (or (= char ?!) (= char ?i)) unsafe-vars) @@ -3772,7 +3788,7 @@ hack-local-variables-confirm 'safe-local-variable-values 'ignored-local-variable-values) unsafe-vars)) - (prog1 (memq char '(?! ?\s ?y)) + (prog1 (memq char '(?! ?\s ?y ?+)) (quit-window t))))))) (defconst hack-local-variable-regexp @@ -3904,6 +3920,7 @@ hack-local-variables-filter (null unsafe-vars) (null risky-vars)) (memq enable-local-variables '(:all :safe)) + (member dir-name permanently-enabled-local-variable-dirs) (hack-local-variables-confirm all-vars unsafe-vars risky-vars dir-name)) (dolist (elt all-vars) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index aadb60e1de7..95eaf9a6bd0 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -166,6 +166,28 @@ files-tests-permanent-local-variables (hack-local-variables) (should (eq lexical-binding nil))))) +(ert-deftest files-tests-permanently-enabled-local-variable-dirs () + ;; permanently-enabled-local-variable-dirs should be risky, + ;; so use it as an arbitrary risky variable. + (let ((test-alist '((permanently-enabled-local-variable-dirs + . "some_val"))) + (fakedir "test1/test2") + (enable-local-eval t)) + (with-temp-buffer + (setq permanently-enabled-local-variable-dirs (list fakedir)) + (hack-local-variables-filter test-alist fakedir) + (should (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq permanently-enabled-local-variable-dirs (list fakedir)) + (setq noninteractive t) + (hack-local-variables-filter test-alist "wrong") + (should-not (equal file-local-variables-alist test-alist))) + (with-temp-buffer + (setq permanently-enabled-local-variable-dirs '()) + (setq noninteractive t) + (hack-local-variables-filter test-alist fakedir) + (should-not (equal file-local-variables-alist test-alist))))) + (defvar files-test-bug-18141-file (ert-resource-file "files-bug18141.el.gz") "Test file for bug#18141.") -- 2.38.1 --=-=-=-- ------------=_1683813302-2954-1-- From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 May 2023 16:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168382139621180 (code B ref 61901); Thu, 11 May 2023 16:10:02 +0000 Received: (at 61901) by debbugs.gnu.org; 11 May 2023 16:09:56 +0000 Received: from localhost ([127.0.0.1]:53237 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1px8rb-0005VY-Ph for submit@debbugs.gnu.org; Thu, 11 May 2023 12:09:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34850) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1px8rZ-0005VE-KE for 61901@debbugs.gnu.org; Thu, 11 May 2023 12:09:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1px8rS-0000LI-Jk; Thu, 11 May 2023 12:09:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=0lqURhzHOVpn6hU+/PxR1o+wgnVZM8/fLQcEdcGa93w=; b=qOhaCuF8s68t ry/ymTHyQLsv9qCb2tXDMMaxJF7pcDb3iFfx1BOjNBfQYAzaPBi/LosUPCotD2n4jb0GSivIqs0cO 9si2GXqoJerKfRBViEsw1aMHpfSEXQhNyQ2NC16T4ypatvMX3BuSPC5V9NYhttvnwzdGhYX97R14f JDlys24BY39E/hRz2je3SaCyUtuRovunGirbfhQSb3hVfzIbvBixGSMzi4M2GNzlCplfUkF7p5w5F YGZtJiPbLUwpMtbQBHzM2I08BJ9ObmMfPryLsoJbpNBrknFSfwUV66cpnqr3Q0+AqtQ9UkAXiti8i ntUQslrc6rUPr9Xr1HG6MQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1px8rR-0004go-RV; Thu, 11 May 2023 12:09:46 -0400 Date: Thu, 11 May 2023 19:10:54 +0300 Message-Id: <83wn1e4zn5.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87ilcy3mdt.fsf@mailbox.org> (message from Antero Mejr on Thu, 11 May 2023 15:42:38 +0000) References: <87r0rpi46l.fsf@mailbox.org> <835y8z55w5.fsf@gnu.org> <87ilcy3mdt.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Antero Mejr > Date: Thu, 11 May 2023 15:42:38 +0000 > > Thanks. I looked it over and found a typo. Patch is attached. Thanks, I removed the redundant text (not exactly the one you proposed to remove). It was your original text, which I replaced with modified one, left there by mistake. > diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi > index b3a8cd8110c..28deddf985d 100644 > --- a/doc/lispref/variables.texi > +++ b/doc/lispref/variables.texi > @@ -1986,7 +1986,7 @@ 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. > +case-insensitive. > @end defvar 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. (And why private email? Please keep the bug address on the CC list.) From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 May 2023 17:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168382740432357 (code B ref 61901); Thu, 11 May 2023 17:51:02 +0000 Received: (at 61901) by debbugs.gnu.org; 11 May 2023 17:50:04 +0000 Received: from localhost ([127.0.0.1]:53300 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxAQW-0008Pm-9W for submit@debbugs.gnu.org; Thu, 11 May 2023 13:50:04 -0400 Received: from mout-p-202.mailbox.org ([80.241.56.172]:48690) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxAQU-0008PB-FL for 61901@debbugs.gnu.org; Thu, 11 May 2023 13:50:03 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4QHKD21ZXRz9skn; Thu, 11 May 2023 19:49:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1683827394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CzhNe7DzxjXN+gHJHRT01UKpTB1h6zBtNXrbeNxs5Go=; b=ka6RwVBD0Is1Lld6hsG1oxAiLNoH3RYABx0HC9RElP8kbTum9poV6YW1tLQNmCBS/TBOAw Qwxno61clhkwGMz6Po7fvP6eyso6JUAjPaBA7gr3gEBdTa5jSjUokfIBmnGNYCRw87AWuX 3/q8JASUudRl1Sl7b+gfua+GbjLNnYnob8Gp2Dazn0/Az3miBECgW2zJ7tq8b5aBdA9cNO nOwqPzQm+oa5M4z6MAdBU9aK5eYdAGWmBgq1D8/W7rG3u0uPUYVLHC3A37a2tJ/y4JPaIb zjhnFX6CbOvbER6HaqhrHLiYn5HHaiZux9kfPnBizKwh1mg+KkF7ee3d+eWh9g== From: Antero Mejr In-Reply-To: <83wn1e4zn5.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 11 May 2023 19:10:54 +0300") References: <87r0rpi46l.fsf@mailbox.org> <835y8z55w5.fsf@gnu.org> <87ilcy3mdt.fsf@mailbox.org> <83wn1e4zn5.fsf@gnu.org> Date: Thu, 11 May 2023 17:49:50 +0000 Message-ID: <87ednm3ght.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain X-MBO-RS-META: mt7ep1hs5d5ny9jf547pwg13nhzx9gnk X-MBO-RS-ID: 5bd48b11224ec8cd571 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Eli Zaretskii writes: >> diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi >> index b3a8cd8110c..28deddf985d 100644 >> --- a/doc/lispref/variables.texi >> +++ b/doc/lispref/variables.texi >> @@ -1986,7 +1986,7 @@ 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. >> +case-insensitive. >> @end defvar > > 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. What if a directory's case sensitivity changes so that it previously did not match, but now does? This could happen with Windows per-directory case sensitivity modifications, mounted disks, or remote paths. 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 That logic would be difficult for users to reason about, so for features with security considerations like this I think it's better to err on the side of safety and simplicity even if the behavior is stricter than expected. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 May 2023 18:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.16838286552948 (code B ref 61901); Thu, 11 May 2023 18:11:02 +0000 Received: (at 61901) by debbugs.gnu.org; 11 May 2023 18:10:55 +0000 Received: from localhost ([127.0.0.1]:53317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxAkh-0000lS-1W for submit@debbugs.gnu.org; Thu, 11 May 2023 14:10:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46492) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxAke-0000lD-Mw for 61901@debbugs.gnu.org; Thu, 11 May 2023 14:10:53 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxAkX-0007xk-Lq; Thu, 11 May 2023 14:10:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=8CdMSpYo/IMUa3FC1+SYdiBM6hziX821SKms5UjvTNA=; b=KPvvOFsdMTSu LS5pIBtBnitlZwwClKKyfpXZAz9GciekwHgL56J//mI0LkBLq9ypnuj/md9J2qjAIqRqw0RZaGhgx DwtmncFP2LUeUe+Kcd7yRR7OJMNdvT7m314rJLg+BMmXPS9CZTSf91GtRDIv81CGf8bHYb0kREvNP VJdHWzYIHU7nZg3vFciWbAI9FJ5LQRJ++Rbo29dkBh1nMQz9czLkOfSjkyeDGp7+DxeEui3S/QknS vLMAZQvccpq0XMS++LXc3x7bjn9G6XUync+wNk3iJMCIQIcAT5plWxMlT9541wjGUtj0WfA+GsM8Z kx7QEzk7Tf56ujvd6GUaPQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxAkW-0000ku-5o; Thu, 11 May 2023 14:10:44 -0400 Date: Thu, 11 May 2023 21:11:52 +0300 Message-Id: <83v8gy4u1j.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87ednm3ght.fsf@mailbox.org> (message from Antero Mejr on Thu, 11 May 2023 17:49:50 +0000) References: <87r0rpi46l.fsf@mailbox.org> <835y8z55w5.fsf@gnu.org> <87ilcy3mdt.fsf@mailbox.org> <83wn1e4zn5.fsf@gnu.org> <87ednm3ght.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Antero Mejr > Cc: 61901@debbugs.gnu.org > Date: Thu, 11 May 2023 17:49:50 +0000 > > Eli Zaretskii 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. > > What if a directory's case sensitivity changes so that it previously did > not match, but now does? This could happen with Windows per-directory > case sensitivity modifications, mounted disks, or remote paths. > > 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 > > That logic would be difficult for users to reason about, so for features > with security considerations like this I think it's better to err on the > side of safety and simplicity even if the behavior is stricter than > expected. We already have all that in file-equal-p. We should just use is there. From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 May 2023 20:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168383589415722 (code B ref 61901); Thu, 11 May 2023 20:12:02 +0000 Received: (at 61901) by debbugs.gnu.org; 11 May 2023 20:11:34 +0000 Received: from localhost ([127.0.0.1]:53431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxCdR-00045W-IG for submit@debbugs.gnu.org; Thu, 11 May 2023 16:11:33 -0400 Received: from mout-p-101.mailbox.org ([80.241.56.151]:50790) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxCdP-00045I-Am for 61901@debbugs.gnu.org; Thu, 11 May 2023 16:11:31 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4QHNMD1C1mz9spZ; Thu, 11 May 2023 22:11:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1683835880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=igujl2IDGymH22rm6a31nTf4kX/py6bacidprBGP9xY=; b=Ug7O/RFwoMUySyKdQ95c0I4urPlMD61sFYI2SZvN95h7vBSMj//w5o9S9zEXfStxn+0p84 o7R/lrJ2b9jKODatF/qeJvEYbXG/UBHtX3p1P5dXQqK60jNRq7l3uecYgDxQx05yOanvm4 +zZbmPGvnu+gRWoHPvGfv8gMZRcGNlFxuikwc/PcjXmVlr4DgtsEsW93e/T+jSzoCZ2ivS jIr03SJVAfujyXqxTABdGssTQHfjf7Put6cpRYIVIIDX7oQcoptHt0mxKIF2l3E51gP3ks JM8kxDBfTHvjy2xGvg69j/jJWN2JBUqc5xBzCRts5FdV3FGrzj+ii226VnVEQQ== From: Antero Mejr In-Reply-To: <83v8gy4u1j.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 11 May 2023 21:11:52 +0300") References: <87r0rpi46l.fsf@mailbox.org> <835y8z55w5.fsf@gnu.org> <87ilcy3mdt.fsf@mailbox.org> <83wn1e4zn5.fsf@gnu.org> <87ednm3ght.fsf@mailbox.org> <83v8gy4u1j.fsf@gnu.org> Date: Thu, 11 May 2023 20:11:16 +0000 Message-ID: <878rdu39y3.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-ID: 02651b620f6ab8d0a73 X-MBO-RS-META: z7sajh636ca9fjqfbceq8kgu5hp9gzgb X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Eli Zaretskii 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). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Handle-case-insensitivity-for-safe-local-variable-di.patch >From 338629b4dc6da17460c96a19178307e6db4bd5d8 Mon Sep 17 00:00:00 2001 From: Antero Mejr 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 --=-=-=-- From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 May 2023 21:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 61901@debbugs.gnu.org Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.16838411301916 (code B ref 61901); Thu, 11 May 2023 21:39:02 +0000 Received: (at 61901) by debbugs.gnu.org; 11 May 2023 21:38:50 +0000 Received: from localhost ([127.0.0.1]:53576 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxDzt-0000Uo-IM for submit@debbugs.gnu.org; Thu, 11 May 2023 17:38:50 -0400 Received: from mout-p-103.mailbox.org ([80.241.56.161]:52772) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxDzo-0000UY-Hv for 61901@debbugs.gnu.org; Thu, 11 May 2023 17:38:48 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4QHQHw5G12z9slX; Thu, 11 May 2023 23:38:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1683841116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MIpj9Pa6d9yP2ab6QkvgNfHvjXKib5Yc+OB0vdnN3Q4=; b=R0pOh58VR0W4cDU4umVO5wctWZ5Vb6BeStHlSTh2UndlSBFXBtGYs16w79JfWcSAg3PoVO fNVaItN0TBjKj5rVDaF3ZZC2Vz1D03rOozckum4nqCw+RZZlFItwnAcwt2sPWsMk3Q6WRr kWVHFg0YUhX9wOvI20uwCfWeE4Ehn8ryovU6GZSAW7cUpFCKt1710C5gKupj8IJq+H7HCZ Ol3FlgmiSi5D2lsIiX/M8g+K89qRhbynO2CsXFPd0rlVi4xPku6sCeRKTXDpwi7p88Wtnl kx+ess9+RLb9mqveTG2J2U3z7gppNqnE/W4m40WCmAD5O4oBegnqHeJ6/CtSrg== From: Antero Mejr In-Reply-To: <878rdu39y3.fsf@mailbox.org> (Antero Mejr's message of "Thu, 11 May 2023 20:11:16 +0000") References: <87r0rpi46l.fsf@mailbox.org> <835y8z55w5.fsf@gnu.org> <87ilcy3mdt.fsf@mailbox.org> <83wn1e4zn5.fsf@gnu.org> <87ednm3ght.fsf@mailbox.org> <83v8gy4u1j.fsf@gnu.org> <878rdu39y3.fsf@mailbox.org> Date: Thu, 11 May 2023 21:38:33 +0000 Message-ID: <874joi35wm.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-RS-ID: 068f17a151ee651d1b2 X-MBO-RS-META: 68w8f7cdy5z5o8xwtcfdc9ok9jqqmtnb X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Antero Mejr writes: > Eli Zaretskii 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). Please ignore that last patch, here is a corrected version with updated docs. Since file-equal-p handles the trailing slash, now it doesn't matter if there is/isn't one. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Handle-case-insensitivity-for-safe-local-variable-di.patch >From 175280bff2574cc7b826025903d4ca1802b7c5e6 Mon Sep 17 00:00:00 2001 From: Antero Mejr 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 sentences in safe-local-variable-directories description about case-sensitivity and trailing slash behaviors. * doc/emacs/custom.texi (Safe File Variables): Remove sentence about safe-local-variable-directories trailing slash behavior. (Bug#61901) --- doc/emacs/custom.texi | 7 +++---- doc/lispref/variables.texi | 8 +++----- lisp/files.el | 5 ++++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index d8abf81c75f..d8221f51425 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -1359,10 +1359,9 @@ certain directories, and skip the confirmation prompt when local variables are loaded from those directories, even if the variables are risky. The variable @code{safe-local-variable-directories} holds the list of such directories. The names of the directories in this list -must be full absolute file names, and should end in a slash. If the -variable @code{enable-remote-dir-locals} has a non-@code{nil} value, -the list can include remote directories as well (@pxref{Remote -Files}). +must be full absolute file names. If the variable +@code{enable-remote-dir-locals} has a non-@code{nil} value, the list +can include remote directories as well (@pxref{Remote Files}). @vindex enable-local-variables The variable @code{enable-local-variables} allows you to change the diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index b3a8cd8110c..4eda035473e 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1982,11 +1982,9 @@ This is a list of directories where local variables are always enabled. Directory-local variables loaded from these directories, 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. +fully-expanded absolute file names. They may also be remote +directories if the variable @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..148f47cbc97 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3934,7 +3934,10 @@ 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) + (and dir-name 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 --=-=-=-- From unknown Tue Jun 17 22:26:14 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 May 2023 11:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61901 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Antero Mejr Cc: 61901-done@debbugs.gnu.org Received: via spool by 61901-done@debbugs.gnu.org id=D61901.168388972425749 (code D ref 61901); Fri, 12 May 2023 11:09:01 +0000 Received: (at 61901-done) by debbugs.gnu.org; 12 May 2023 11:08:44 +0000 Received: from localhost ([127.0.0.1]:54179 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxQdf-0006hF-SS for submit@debbugs.gnu.org; Fri, 12 May 2023 07:08:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxQdd-0006h1-HL for 61901-done@debbugs.gnu.org; Fri, 12 May 2023 07:08:42 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQdX-0007zE-QC; Fri, 12 May 2023 07:08:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=QesvcLbJbIh0gNpaUHC6d/lwCA+NJkCt/y6vM3bLGI8=; b=Ee3iqVBjDrnC 4NO6UYLYboTSIK/p8iKkZpUAJ3JgDBmRouaSrz+er1D7yzZQYmxo/fTMdBZcVgtthjx2NxlQ+v4zM bB8VDRNUFMLAt/mm7CafBBAQ0ShbnzwYwDjWb8YUf9Om2mbVDTl0IwF0eiUE2huS4f1L/joglLa4U lXVI81TU54sf5DLLmFRewZMuxLLvHqq1IqwsOBaOtL+DLqg0bra6x0Dj5yGe9+ir1iOwRfjhBOZjg xYfYDz7hGzdEJyUErSIEFO96bT225WUfxZ1JvflBZ4t8uV77Udlq1vrOOx14U1Lu8/+F5Pf5kC7dc QwtqOt1NjKTRXruNqexc/w==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQdX-0005ub-1H; Fri, 12 May 2023 07:08:35 -0400 Date: Fri, 12 May 2023 14:09:46 +0300 Message-Id: <83v8gx3ix1.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <874joi35wm.fsf@mailbox.org> (message from Antero Mejr on Thu, 11 May 2023 21:38:33 +0000) References: <87r0rpi46l.fsf@mailbox.org> <835y8z55w5.fsf@gnu.org> <87ilcy3mdt.fsf@mailbox.org> <83wn1e4zn5.fsf@gnu.org> <87ednm3ght.fsf@mailbox.org> <83v8gy4u1j.fsf@gnu.org> <878rdu39y3.fsf@mailbox.org> <874joi35wm.fsf@mailbox.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Antero Mejr > Cc: 61901@debbugs.gnu.org > Date: Thu, 11 May 2023 21:38:33 +0000 > > Please ignore that last patch, here is a corrected version with updated > docs. Since file-equal-p handles the trailing slash, now it doesn't > matter if there is/isn't one. Thanks, installed. This change broke files-tests, so I installed a fix there.