From b7a3fce17b8bf7bf823386e016d908945a3fd6ba Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 16 Jul 2018 11:10:51 +0600 Subject: [PATCH] simplify has_prefixed_route() --- src/router.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) 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..]) } }