Subject: bug#74208: 31.0.50; minibuffer read-file-name-default mutates global value of default-directory incorrectly

From: Eli Zaretskii <[email-masked]>
Date: Sun, 10 Nov 2024 12:00:48 +0200

> Date: Sun, 10 Nov 2024 12:30:07 +0530 (IST)
> Cc: [email-masked], [email-masked]
> From: Madhu <[email-masked]>
> 
> >> -                              (expand-file-name dir))))
> >> +                              (expand-file-name dir)))
> >> +                        (default-directory (if (file-name-absolute-p dir)
> >> +                                               dir default-directory)))
> > You probably meant to use let*, right?
> 
> Oops. yes, of course.
> 
> > But anyway, I don't understand the logic: expand-file-name always
> > returns an absolute file name, so the test will always succeed.  What
> > did I miss?
> 
> for the example in the thread,
> ffap.el:(ffap-read-file-or-url) calls read-file-name-default, via
>               (funcall #'read-file-name-default prompt guess guess) =>
> 
>   read-file-name-default("Find file or URL: " "http://example.com" "http://example.com")
> 
> (read-file-name-default PROMPT &optional DIR DEFAULT-FILENAME
>  MUSTMATCH INITIAL PREDICATE)
> 
> The problem is that the parameter DIR == "http://example.com" was
> getting bound to default-directory with undesirable results. DIR a url
> not a file name but a url. and since expand-file-name behaves like
> this:
> 
> (expand-file-name "http://example.com" "~") ->  "http://example.com"

That's not what I see.  I see this:

  (expand-file-name "http://example.com" "~")
    => /my/home/directory/http:/example.com

In what version of Emacs do you see your result?
Is that in "emacs -Q"?

In any case, the code you propose calls

  (expand-file-name dir)

without the 2nd argument.

> it can probably be used to determine that DIR is not a legit filename
> and default directory should not be bound to it.

I don't see how expand-file-name could help here, see above.