Subject: bug#46219: 28.0.50; Suboptimal results of `file-relative-name' with mixed-quoted filenames

From: Eli Zaretskii <[email-masked]>
Date: Sun, 31 Jan 2021 22:08:29 +0200

> From: Philipp Stephani <[email-masked]>
> Date: Sun, 31 Jan 2021 20:26:20 +0100
> 
> $ emacs -Q -batch -eval '(progn (princ (file-relative-name "/:/bin/true" "/bin")) (terpri) (princ (file-relative-name "/bin/true" "/:/bin")) (terpri))'
> ../:/bin/true
> ../../bin/true
> 
> I guess these aren't *technically* wrong, but probably not what's
> intended here.  I'd expect a return value of "true" in both cases.

I think your expectations are misplaced.  The doc string says:

  This function returns a relative file name that is equivalent to FILENAME
  when used with that default directory as the default.

So you should use

   (file-relative-name "/:/bin/true" "/:/bin")

A useful rule of thumb to remember is that this function treats its
argument as a literal string, it doesn't apply any file-name
semantics.