From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Madhu Newsgroups: gmane.emacs.bugs Subject: bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly Date: Tue, 05 Nov 2024 07:39:24 +0530 (IST) Message-ID: <20241105.073924.1479117425130782406.enometh@meer.net> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25903"; mail-complaints-to="usenet@ciao.gmane.io" To: 74208@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 05 03:10:26 2024 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 1t891U-0006X1-Th for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Nov 2024 03:10:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8919-0000L6-J9; Mon, 04 Nov 2024 21:10:03 -0500 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 1t8918-0000Ke-C5 for bug-gnu-emacs@gnu.org; Mon, 04 Nov 2024 21:10:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8918-0000HH-2c for bug-gnu-emacs@gnu.org; Mon, 04 Nov 2024 21:10:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Mime-Version:From:Date:To:Subject; bh=Dp87IPl74cORPr2aGfbdeLOfd7YRXibA8bBr3BwoF9Y=; b=t6kxoOI36v/WTPS5E6otePqTOTAb8K10O/+5tEOjXDnUEDJuC8/7zBnOvrzD332kbvBlPKQhOKwHWnkU4GPpHjDOPXV/LptK0vyXBXDIvK9BESW69yOTLTGA/XER4b7zBkGkB39drs5WDlETqIpUNeKf1UnFYwlKXK9hmo8pn3kRlKwPiOxjXoyI0EnfLiQiYLgS8iWNREWhcfgALc8HkXwpgSG5l6sVOZhqE/OP1I0jJKBzw+8dA0ChvLaC/W7KlkJNdaZwoTWh4aOibp0gMtYgcwAAVM1CMbjhyCwf4w6WaA14PDih2G2c+SXweVoH3n42r0MVVUWaEbQznvRAKA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t8917-0002Gr-TV for bug-gnu-emacs@gnu.org; Mon, 04 Nov 2024 21:10:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Madhu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Nov 2024 02:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74208 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17307725758704 (code B ref -1); Tue, 05 Nov 2024 02:10:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Nov 2024 02:09:35 +0000 Original-Received: from localhost ([127.0.0.1]:43004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t890h-0002GK-9T for submit@debbugs.gnu.org; Mon, 04 Nov 2024 21:09:35 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:33646) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t890f-0002GC-Lb for submit@debbugs.gnu.org; Mon, 04 Nov 2024 21:09:34 -0500 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 1t890f-0000Id-Fe for bug-gnu-emacs@gnu.org; Mon, 04 Nov 2024 21:09:33 -0500 Original-Received: from smtp0.ctinetworks.com ([205.166.61.207]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t890d-0000Fu-JF for bug-gnu-emacs@gnu.org; Mon, 04 Nov 2024 21:09:33 -0500 X-ctinetworks-Watermark: 1731636565.02982@taQz5AdbyGXdI6nORWgj5A X-ctinetworks-Envelope-From: enometh@meer.net X-ctinetworks-VirusCheck: Found to be clean X-ctinetworks-Message-ID: 4E5755F57.AAE35 Original-Received: from localhost (unknown [117.254.36.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: enometh@meer.net) by smtp0.ctinetworks.com (Postfix) with ESMTPSA id 4E5755F57 for ; Mon, 4 Nov 2024 21:09:24 -0500 (EST) X-Mailer: Mew version 6.9 on Emacs 31.0.50 Received-SPF: pass client-ip=205.166.61.207; envelope-from=enometh@meer.net; helo=smtp0.ctinetworks.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:294893 Archived-At: minibuffer.el: (read-file-name-default) has the following code: ``` (minibuffer-with-setup-hook (lambda () (setq default-directory dir) ... (set-syntax-table minibuffer-local-filename-syntax)) ``` This mutates the global binding of default-directory which is incorrect. To demonstrate the problem, in emacs -Q (insert "http://example.com") (setq enable-recursive-minibuffers t) position point at in the middle of the string http://example.com M-: (ffap) ;; while waiting for input M-: default-directory ;; => default-directory is bound to "http://example.com" M-: (shell-command "echo foo") ; ;=> ;; Debugger entered--Lisp error: (file-missing "Setting current directory" "No such file or directory" "http://example.com/") I think this can be addressed by binding default-directory before modifying it. ``` diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3671,6 +3671,7 @@ read-file-name-default (expand-file-name dir)))) (minibuffer-with-setup-hook (lambda () + (let ((default-directory default-directory)) (setq default-directory dir) ;; When the first default in `minibuffer-default' ;; duplicates initial input `insdef', @@ -3689,7 +3690,7 @@ read-file-name-default (with-current-buffer (window-buffer (minibuffer-selected-window)) (read-file-name--defaults dir initial)))) - (set-syntax-table minibuffer-local-filename-syntax)) + (set-syntax-table minibuffer-local-filename-syntax))) (completing-read prompt 'read-file-name-internal pred require-match insdef 'file-name-history default-filename))) ``` [I'm sending this before I forget so it can be reviewed, but I can send this patch as as attachment if needed, and it'll take some more time until I figure out how to write a test for it and test it.]