From 7a2bc0ce4f0c218f70c4d4d9f9b409bb20f1fedf Mon Sep 17 00:00:00 2001 From: Oakchris1955 <80592203+Oakchris1955@users.noreply.github.com> Date: Sat, 14 Sep 2024 15:54:07 +0300 Subject: [PATCH] fix: PathBuf's `.parent()` method wouldn't behave as expected --- src/path.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/path.rs b/src/path.rs index b53b1a7..d2b78aa 100644 --- a/src/path.rs +++ b/src/path.rs @@ -125,7 +125,12 @@ impl PathBuf { pub fn parent(&self) -> PathBuf { if self.inner.len() > 1 { let mut pathbuf = self.clone(); + + if pathbuf.is_dir() { + pathbuf.inner.pop_back(); + } pathbuf.inner.back_mut().unwrap().clear(); + pathbuf } else { PathBuf::new()