Skip to content

Path does not properly split windows path when running on non-windows Os #103589

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

Closed
kaifastromai opened this issue Oct 26, 2022 · 2 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@kaifastromai
Copy link

I tried this code:

fn main() {
    println!("Hello, world!");
    let p=std::path::Path::new("test1\\test2\\test3");
    
    println!("{:?}",p.components().last())
}

The result I would expect should be "test3", but it instead returns the entire path item. An example can be seen on the playground

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (bed4ad65b 2022-10-25)
binary: rustc
commit-hash: bed4ad65bf7a1cef39e3d66b3670189581b3b073
commit-date: 2022-10-25
host: aarch64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2
@kaifastromai kaifastromai added the C-bug Category: This is a bug. label Oct 26, 2022
@the8472
Copy link
Member

the8472 commented Oct 26, 2022

The behavior of the std::path module is platform-dependent. On unix inputs are treated as unix-paths, on windows as windows-paths. So this is expected behavior.

@the8472
Copy link
Member

the8472 commented Oct 26, 2022

#66621 proposes a potential solution, so I'm closing this as a dupe of that.

@the8472 the8472 closed this as completed Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants