Skip to content

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

@zuobaoquan

Description

@zuobaoquan
#[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"));
}

Activity

nagisa

nagisa commented on Nov 10, 2019

@nagisa
Member

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.

Arnavion

Arnavion commented on Jul 30, 2020

@Arnavion

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?

reopened this on Jul 30, 2020
added
O-windowsOperating system: Windows
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
T-libsRelevant to the library team, which will review and decide on the PR/issue.
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 30, 2020
retep998

retep998 commented on Jul 30, 2020

@retep998
Contributor

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

ChrisDenton commented on Sep 11, 2020

@ChrisDenton
Member

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.

added a commit that references this issue on Dec 2, 2021
6e5f4c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @retep998@nagisa@zuobaoquan@Arnavion@ChrisDenton

      Issue actions

        Path::starts_with and ends_with should be case-insensitive on Windows · Issue #66260 · rust-lang/rust