diff --git a/src/router.rs b/src/router.rs index 56f304947..fe3ecb94d 100644 --- a/src/router.rs +++ b/src/router.rs @@ -1,7 +1,6 @@ use std::cmp::min; use std::collections::HashMap; use std::hash::{Hash, Hasher}; -use std::path::Path; use std::rc::Rc; use regex::{escape, Regex}; @@ -159,19 +158,11 @@ impl ResourceInfo { /// It will not match against prefix in case it's not given. For example for `/name` /// with a `/test` prefix would return `false` pub fn has_prefixed_route(&self, path: &str) -> bool { - if self.prefix == 0 { - return self.has_route(path); + let prefix = self.prefix as usize; + if prefix >= path.len() { + return false; } - - let path_matcher = Path::new(if path.is_empty() { "/" } else { path }); - let router_prefix = Path::new(&path[..(self.prefix as usize)]); - if let Ok(p) = path_matcher.strip_prefix(router_prefix) { - if let Some(p_str) = p.to_str() { - return self.has_route(&format!("/{}", p_str)); - } - } - - false + self.has_route(&path[prefix..]) } }