Path::strip_prefix() improperly strips trailing slash
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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)
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 278a90913daf77077910).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the std::path::Path::strip_prefix entry point and reproduce the stable or nightly example from the issue. Compare the returned display with the expected bar/baz/ result, then add coverage for the trailing-slash case so the corrected behavior is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100