From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Antero Mejr via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61901: 30.0.50; [PATCH v3] Add safe-local-variable-directories variable. Date: Tue, 25 Apr 2023 16:40:07 +0000 Message-ID: <87354nlxug.fsf@mailbox.org> References: <87sfeoksuk.fsf@mailbox.org> Reply-To: Antero Mejr Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14129"; mail-complaints-to="usenet@ciao.gmane.io" To: 61901@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 25 18:41:21 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prLjE-0003VX-SF for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 Apr 2023 18:41:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prLiy-0002hi-0c; Tue, 25 Apr 2023 12:41:04 -0400 Original-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 1prLiw-0002hX-PS for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 12:41:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prLiw-0001EX-HD for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 12:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1prLiv-00045k-UM for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 12:41:01 -0400 X-Loop: help-debbugs@gnu.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 Original-Received: via spool by 61901-submit@debbugs.gnu.org id=B61901.168244082415667 (code B ref 61901); Tue, 25 Apr 2023 16:41:01 +0000 Original-Received: (at 61901) by debbugs.gnu.org; 25 Apr 2023 16:40:24 +0000 Original-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 Original-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 Original-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== X-MBO-RS-ID: 02986b6babcc8640436 X-MBO-RS-META: 5ryudexbbhwgrc74r5h3ebd1w4s19zmn X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260629 Archived-At: --=-=-= 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 --=-=-=--