From 60ae814fd6d080ca742d2a3b85cfaf3b969d1948 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Sun, 23 Jan 2022 18:00:33 -0800 Subject: [PATCH] trim trailing matches for the greater good Signed-off-by: Erik Hollensbe --- src/path.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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());