diff --git a/ntex-router/CHANGES.txt b/ntex-router/CHANGES.txt index 89060021..b6eacc3b 100644 --- a/ntex-router/CHANGES.txt +++ b/ntex-router/CHANGES.txt @@ -1,5 +1,9 @@ # Changes +## [0.3.3] - 2020-04-11 + +* Fix `/` prefix match + ## [0.3.2] - 2020-04-06 * Fix IdxSegment item for paths with no root diff --git a/ntex-router/Cargo.toml b/ntex-router/Cargo.toml index 3f94bd67..33f81b8c 100644 --- a/ntex-router/Cargo.toml +++ b/ntex-router/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-router" -version = "0.3.2" +version = "0.3.3" authors = ["Nikolay Kim "] description = "Path router" keywords = ["ntex"] diff --git a/ntex-router/src/resource.rs b/ntex-router/src/resource.rs index 207a3f2f..0c18d81e 100644 --- a/ntex-router/src/resource.rs +++ b/ntex-router/src/resource.rs @@ -761,6 +761,11 @@ mod tests { #[test] fn test_resource_prefix() { + let tree = Tree::new(&ResourceDef::prefix("/"), 1); + assert_eq!(tree.find(&mut Path::new("/")), Some(1)); + assert_eq!(tree.find(&mut Path::new("/a")), Some(1)); + assert_eq!(tree.find(&mut Path::new("/a/test/test")), Some(1)); + let tree = Tree::new(&ResourceDef::prefix("/name"), 1); assert_eq!(tree.find(&mut Path::new("/name")), Some(1)); assert_eq!(tree.find(&mut Path::new("/name/")), Some(1)); diff --git a/ntex-router/src/tree.rs b/ntex-router/src/tree.rs index a21adc01..55c82c18 100644 --- a/ntex-router/src/tree.rs +++ b/ntex-router/src/tree.rs @@ -208,7 +208,7 @@ impl Tree { if path == "/" { for val in &self.value { let v = match val { - Value::Slesh(v) | Value::Prefix(v) => *v, + Value::Slesh(v) | Value::Prefix(v) | Value::PrefixSlesh(v) => *v, _ => continue, }; if check(v, resource) { @@ -225,6 +225,16 @@ impl Tree { return Some(v); } } + } else { + for val in &self.value { + let v = match val { + Value::PrefixSlesh(v) => *v, + _ => continue, + }; + if check(v, resource) { + return Some(v); + } + } } let path = if path.starts_with('/') {