trim trailing matches for the greater good

Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
Erik Hollensbe
2022-01-23 18:00:33 -08:00
parent 728b96b5ba
commit 60ae814fd6
+11 -1
View File
@@ -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<Params, Error> {
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());