Skip to content

Path::components().as_path() for "///a/b" failing to normalize multiple slashes for root dir on Unix #83912

@programmerjake

Description

@programmerjake

I'd expect the path to be normalized to "/a/b" since that is a substring of "///a/b".

On some Unix implementations a leading // is special, but the Unix and POSIX specs state that a leading /// is equivalent to just one /. On Linux, // is also the same as /, though it has been proposed for that to change.
Stack Exchange: On what systems is //foo/bar different from /foo/bar?

use std::path::Path;

fn main() {
    let expected = "/a/b";
    let actual = Path::new("///a/b").components().as_path().to_str().unwrap();
    assert_eq!(expected, actual);
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
    Finished release [optimized] target(s) in 3.78s
     Running `target/release/playground`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"/a/b"`,
 right: `"///a/b"`', src/main.rs:6:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions