diff --git a/src/path.rs b/src/path.rs index d22110d..371f641 100644 --- a/src/path.rs +++ b/src/path.rs @@ -21,6 +21,9 @@ impl Ord for Path { impl Path { pub(crate) fn new(path: String) -> Self { let mut parts = Self::default(); + + let path = path.trim_end_matches("/"); + if !path.contains("/") { return Self::default(); } @@ -64,7 +67,9 @@ impl Path { } pub(crate) fn extract(&self, provided: String) -> Result { - if (provided == "" || provided == "/") && self.eq(&Self::default()) { + let provided = provided.trim_end_matches("/"); + + if provided == "" && self.eq(&Self::default()) { return Ok(Params::default()); } @@ -212,6 +217,11 @@ mod tests { Params::default() ); + assert_eq!( + Path::new("/account/".to_string()), + Path::new("/account".to_string()) + ); + assert_eq!(Path::default().to_string(), "/".to_string()); let path = Path::new("/".to_string());