Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path#relative_to? across equivalent Windows roots #15591

Open
HertzDevil opened this issue Mar 23, 2025 · 0 comments
Open

Path#relative_to? across equivalent Windows roots #15591

HertzDevil opened this issue Mar 23, 2025 · 0 comments
Labels
platform:windows Windows support based on the MSVC toolchain / Win32 API status:discussion topic:stdlib:files

Comments

@HertzDevil
Copy link
Contributor

Path#relative_to? requires both the target and the base paths to have the exactly same anchor, otherwise nil is returned. It might be surprising to some that alternative Windows directory separators are not considered:

Path["C:/foo"].relative_to?(Path["C:\\foo"]) # => nil

Resolving this part is relatively easy; as long as the drive letters are identical, it should not matter which slash is used.

The complicated part arises when dealing with local device paths (#15590), because either the target or base can start with \\., and it could be equivalent to some other normal or UNC path:

Path["//./C:/foo"].relative_to?(Path["C:/bar"]) # => "../foo"
Path["//./D:/foo"].relative_to?(Path["C:/bar"]) # => nil

Path["//./UNC/server/share/foo"].relative_to?(Path["//server/share/bar"]) # => "../foo"

Path["C:/foo"].relative_to?(Path["//./C:/bar"]) # => "../foo"
Path["D:/foo"].relative_to?(Path["//./C:/bar"]) # => "../../D:/foo"

Path["//server/share/foo"].relative_to?(Path["//./C:/bar"]) # => "../../UNC/server/share/foo"

These can be done purely lexically, without any filesystem access. So I wonder if Path#relative_to? should take care of these cases as well.

@HertzDevil HertzDevil added platform:windows Windows support based on the MSVC toolchain / Win32 API status:discussion topic:stdlib:files labels Mar 23, 2025
@HertzDevil HertzDevil moved this to Todo in Windows Support Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:windows Windows support based on the MSVC toolchain / Win32 API status:discussion topic:stdlib:files
Projects
Status: Todo
Development

No branches or pull requests

1 participant