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::starts_with and ends_with should be case-insensitive on Windows #66260

Closed
zuobaoquan opened this issue Nov 10, 2019 · 4 comments · Fixed by #91464
Closed

Path::starts_with and ends_with should be case-insensitive on Windows #66260

zuobaoquan opened this issue Nov 10, 2019 · 4 comments · Fixed by #91464
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@zuobaoquan
Copy link

#[test]
fn test_path_starts_with() {
    let path = PathBuf::from(r"C:\A\b");
    assert!(path.starts_with(r"C:\a"));
}

#[test]
fn test_path_ends_with() {
    let path = PathBuf::from(r"C:\a\b");
    assert!(path.ends_with("B"));
}
@nagisa
Copy link
Member

nagisa commented Nov 10, 2019

Case sensitivity is a property of the filesystem, not operating system and these functions are filesystem agnostic.

As thus, this issue is not actionable. Closing. If you feel differently please complain and I’ll reopen.

@nagisa nagisa closed this as completed Nov 10, 2019
@Arnavion
Copy link

It's fine if the functions want to be case-sensitive, but their docs need to be changed to point this out explicitly and noticeably. Every Windows user is going to assume that the functions are case-insensitive just like they are in other languages on the platform. (I imagine OSX users will have the same expectation?)

It's made slightly worse because PrefixComponent is handled in a special way that makes Path::new("C:\\Windows").starts_with(Path::new("c:")) evaluate to true despite the mismatched case. So someone using that as a quick test of their assumption would end up with the wrong idea.

@nagisa Would you mind reopening for this reason?

@nagisa nagisa reopened this Jul 30, 2020
@nagisa nagisa added O-windows Operating system: Windows A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 30, 2020
@retep998
Copy link
Member

I think it would also be good to have a crate like same-file provide a starts_with that does hit the filesystem. Such an API would also be able to detect when the same folder is specified but using alternate prefixes or mount points or through symbolic links.

@ChrisDenton
Copy link
Member

ChrisDenton commented Sep 11, 2020

The driver letter is a symlink in the Object Manager and lookup is always case-insensitive. Folders are located on the filesystem and may or may not be case sensitive.

I do think platform specific behaviour should be documented if it can be a source of confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants