Path.join("folder1/subfolder2/", "/")
"folder1/subfolder2/."
Path.join("folder1/subfolder2/", "/")
"folder1/subfolder2/"
Dot, in the end, is weird and unexpected, is this bug?
Didn't find this behavior in documentation
Yup, it is a bug. :) We should have a special case to handle when the right side is "/". A PR would be welcome!
To be clear, I think the result should be "folder1/subfolder2" as join removes trailing slashes.
Do you want to take a stab at this @SofaKing18? Could also look into it.
For the sake of completion, the issue also exists with join/1. E.g.
Path.join(["/foo", "bar", "/"]) -> "/foo/bar/."
I would like to make PR, but if @cybrox want - go for it :)
@SofaKing18 Ah, feel free to do so then. I'm just trying to pick up issues that the reporter does not PR themselves ;)
@josevalim Path.join/2 states _The right path will always be expanded to its relative format_, I feel a hint to this behaviour should be added to Path.join/1 as well. I think the following can be confusing?
iex(13)> Path.join(["", "/", "/usr/bin"])
"./usr/bin"
iex(14)> Path.join(["/", "/", "/usr/bin"])
"/./usr/bin"
Path.join/1 is implemented on top of Path.join/2 so fixing one should fix the other.
I know. Fixing the reported issue would fix the second example, the first one would still persist, though. Shouldn't an empty list element be ignored instead of making the whole path relative?
Considering the following works fine, it seems a bit odd that a leading empty element would have such a huge impact while an empty element anywhere else does not matter.
iex(7)> Path.join(["/usr", "", "", "/bin", "/", "share"])
"/usr/bin/share"