diff --git a/src/application.rs b/src/application.rs index 3ef753f5f..407268322 100644 --- a/src/application.rs +++ b/src/application.rs @@ -447,11 +447,8 @@ where { let mut path = path.trim().trim_right_matches('/').to_owned(); if !path.is_empty() && !path.starts_with('/') { - path.insert(0, '/') - } - if path.len() > 1 && path.ends_with('/') { - path.pop(); - } + path.insert(0, '/'); + }; self.parts .as_mut() .expect("Use after finish") diff --git a/src/scope.rs b/src/scope.rs index 6e7f28985..4ce4901af 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -313,14 +313,7 @@ impl Scope { /// } /// ``` pub fn handler>(mut self, path: &str, handler: H) -> Scope { - let mut path = path.trim().trim_right_matches('/').to_owned(); - if !path.is_empty() && !path.starts_with('/') { - path.insert(0, '/') - } - if path.len() > 1 && path.ends_with('/') { - path.pop(); - } - + let path = insert_slash(path.trim().trim_right_matches('/')); Rc::get_mut(&mut self.router) .expect("Multiple copies of scope router") .register_handler(&path, Box::new(WrapHandler::new(handler)), None);