all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly
@ 2024-11-05  2:09 Madhu
  2024-11-09 11:11 ` Eli Zaretskii
  2024-11-09 16:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 30+ messages in thread
From: Madhu @ 2024-11-05  2:09 UTC (permalink / raw)
  To: 74208

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.]






^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2024-12-09  8:17 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05  2:09 bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly Madhu
2024-11-09 11:11 ` Eli Zaretskii
2024-11-09 16:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-10  0:57   ` Madhu
2024-11-10  6:00     ` Eli Zaretskii
2024-11-10  7:00       ` Madhu
2024-11-10 10:00         ` Eli Zaretskii
2024-11-10 10:41           ` Madhu
2024-11-10 10:45             ` Eli Zaretskii
2024-11-10 11:17               ` Madhu
2024-11-10 11:26                 ` Eli Zaretskii
2024-11-10 16:54         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-11  2:17           ` Madhu
2024-11-11  3:40             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-23 12:25               ` Eli Zaretskii
2024-11-23 14:56                 ` Madhu
2024-11-24  3:00                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24  7:19                   ` Eli Zaretskii
2024-12-07 12:20                     ` Eli Zaretskii
2024-12-07 17:23                       ` Madhu
2024-12-07 18:27                         ` Eli Zaretskii
2024-12-08  8:46                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 10:49                           ` Madhu
2024-12-08 11:33                             ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 11:59                               ` Madhu
2024-12-08 15:13                                 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 16:26                                   ` Madhu
2024-12-08 17:28                                     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-08 23:42                                       ` Madhu
2024-12-09  8:17                                         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.