Subject: bug#36490: 26.1; directory-files-recursively breaks when it encounters a directory named "~"

From: Eli Zaretskii <[email-masked]>
Date: Tue, 09 Jul 2019 18:35:46 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Date: Mon, 08 Jul 2019 23:08:46 +0200
> Cc: [email-masked]
> 
> Actually, the doc string of expand-file-name is either wrong, or the
> implementation is.
> 
> It says:
> 
> ---
> An initial ‘~/’ expands to your home directory.
> An initial ‘~USER/’ expands to USER’s home directory.
> ---
> 
> Assuming the "An initial" refers to the first parameter, then
> 
> (expand-file-name "~/" "/tmp/")
> => "/home/larsi/"
> 
> works as advertised, but
> 
> (expand-file-name "~" "/tmp/")
> => "/home/larsi"
> 
> is a different thing: "~" is a perfectly valid file name, so having this
> function map that to something else is just...  wrong.

If you want "~" to be interpreted literally, you need to protect it
with "/:".

> (expand-file-name "~larsi" "/tmp/")
> => "/home/larsi"
> 
> is the same: Also wrong and undocumented.

Why would we want to document that?

> The doc string continues with further confusion:
> 
> ---
> See also the function ‘substitute-in-file-name’.
> ---
> 
> See it for...  what?

For expanding environment variables, and for the special effect of
"//" etc.

> So what to do here?  I think the current, undocumented
> 
> (expand-file-name "~" "/tmp/")
> => "/home/larsi"
> 
> must surely be an error, and that should be fixed instead of the
> callers?  Opinions?

It is not an error.