Skip to content

Path::strip_prefix() improperly strips trailing slash #148267

@MikkelPaulson

Description

@MikkelPaulson

I tried this code:

use std::path::Path;

let path = Path::new("/foo/bar/baz/");
assert_eq!("/foo/bar/baz/", path.display().to_string());

let stripped_path = path.strip_prefix("/foo").unwrap();
println!("{}", stripped_path.display());

Expected output: bar/baz/ (input with the to-strip part removed)

Actual output: bar/baz (input with the to-strip part and the trailing slash removed)

Playground

This is particularly relevant when/if #142503 lands, which further surfaces that inconsistency: playground

Meta

Reproduces in the stable and nightly builds currently on playground: 1.90.0 and 1.93.0-nightly (2025-10-28 278a909).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-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

    No branches or pull requests

    Issue actions