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 parsing / joining should auto-simplify the path #10

Open
epage opened this issue Feb 11, 2018 · 0 comments
Open

Path parsing / joining should auto-simplify the path #10

epage opened this issue Feb 11, 2018 · 0 comments

Comments

@epage
Copy link

epage commented Feb 11, 2018

use std::path::PathBuf;

fn main() {
    let path = PathBuf::from("empty//dot/./parent/../");
    println!("base {:?}", path);
    println!("join(empty) {:?}", path.join(PathBuf::from("")));
    println!("join(dot) {:?}", path.join(PathBuf::from(".")));
    println!("join(./) {:?}", path.join(PathBuf::from("./")));
}

playground

From what I gather, std::path seems to focus on being a low level API that can work on non-traditional systems. This means it cannot assume what is intended by extraneous /s, ., or ..`.

Yes, there is canonicalize but sometimes you need it done on relative paths when doing comparisons.

Python's pathlib automatically cleans up paths like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant