GNU bug report logs -
#74208
31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly
Previous Next
Reported by: Madhu <enometh <at> meer.net>
Date: Tue, 5 Nov 2024 02:10:01 UTC
Severity: normal
Found in version 31.0.50
Fixed in version 31.1
Done: Michael Albinus <michael.albinus <at> gmx.de>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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.]
This bug report was last modified 159 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.