diff --git a/README.md b/README.md index 3b2df4e..93a85f2 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ - **Fast**: See benchmark -- **Micro**: The [src/lib.rs](src/lib.rs) file is ~407 lines of code (Includes comments) +- **Micro**: The [src/lib.rs](src/lib.rs) file is ~405 lines of code (Includes comments) - **Flexible**: diff --git a/src/lib.rs b/src/lib.rs index 9452966..1595487 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -193,7 +193,7 @@ impl Node { NodeKind::Static(ref s) => { let l = loc(s, p); - if l == 0 || l < s.len() { + if l < s.len() { None } else if l == s.len() && l == p.len() { Some( @@ -297,7 +297,7 @@ impl PathTree { #[inline] pub fn new() -> Self { Self { - root: Node::new(NodeKind::Static("/".to_owned())), + root: Node::new(NodeKind::Static("".to_owned())), params: 0, } } @@ -310,8 +310,6 @@ impl PathTree { let mut most = 0; - path = path.trim_start_matches('/'); - if path.is_empty() { node.data.replace(data); return self; diff --git a/tests/basic.rs b/tests/basic.rs index 030279f..9540f1d 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -5,7 +5,8 @@ use rand::seq::SliceRandom; fn new_tree() { let mut tree: PathTree = PathTree::default(); - const ROUTES: [&str; 13] = [ + const ROUTES: [&str; 14] = [ + "", "/", "/users", "/users/:id", @@ -21,7 +22,8 @@ fn new_tree() { "/users/repos/*any", ]; - const VALID_URLS: [&str; 13] = [ + const VALID_URLS: [&str; 14] = [ + "", "/", "/users", "/users/fundon", @@ -38,6 +40,7 @@ fn new_tree() { ]; let valid_res = vec![ + vec![], vec![], vec![], vec![("id", "fundon")],