rejeep / f.el

Modern API for working with files and directories in Emacs
GNU General Public License v3.0
680 stars 68 forks source link

f-join not working as expected #100

Closed jcs090218 closed 2 years ago

jcs090218 commented 3 years ago

I am trying to join two path using f-join function.

(message "%s" (f-join "C:/Program Files (x86)/Microsoft Visual Studio/" "/Community/VC/Tools/MSVC/"))

Output

c:/Community/VC/Tools/MSVC/

Expected Output

C:/Program Files (x86)/Microsoft Visual Studio/Community/VC/Tools/MSVC/

Any idea? 😕

Phundrak commented 2 years ago

It seems the bug comes from somewhere in expand-file-name, as seen with the following example:

(expand-file-name "/Community/VC/Tools/MSVC/"
                  "C:/Program Files (x86)/Microsoft Visual Studio/")
;; => "c:/Community/VC/Tools/MSVC/"

This might be an Emacs bug. Tested in Emacs 28.1. However, the following works:

(f-join "C:/Program Files (x86)/Microsoft Visual Studio/"
        "Community/VC/Tools/MSVC/")
;; => "c:/Program Files (x86)/Microsoft Visual Studio/Community/VC/Tools/MSVC/"

The leading / might be what causes the bug.

Phundrak commented 2 years ago

As the current behavior of f-join follows the behavior of expand-file-name, and as changing it might lead to breaking changes, I decided to tag this issue with wontfix.

This is also the behavior of several other programing languages.

Python

from os.path import join
print(join("C:/path/to", "/a"))
/a

C++

#include <filesystem>
namespace fs = std::filesystem;
int main() {
    fs::path p1 = "C:/path/to";
    p1 /= "/a";
    std::cout << p1 << '\n';
}
/a