mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 04:47:39 +03:00
Allow nested prefixed resources
This commit is contained in:
parent
a66efe4256
commit
21803f9e2f
5 changed files with 46 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [0.3.6] - 2020-09-11
|
||||
|
||||
* Allow nested prefixed resources
|
||||
|
||||
## [0.3.5] - 2020-05-09
|
||||
|
||||
* Handle non-prefix and prefix resources combinations
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-router"
|
||||
version = "0.3.5"
|
||||
version = "0.3.6"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "Path router"
|
||||
keywords = ["ntex"]
|
||||
|
|
|
@ -852,6 +852,20 @@ mod tests {
|
|||
assert_eq!(&resource["name"], "test2");
|
||||
assert_eq!(&resource[0], "test2");
|
||||
assert_eq!(resource.path(), "/subpath1/subpath2/index.html");
|
||||
|
||||
// nested
|
||||
let mut tree = Tree::new(&ResourceDef::prefix("/prefix/{v1}/second/{v2}"), 1);
|
||||
tree.insert(&ResourceDef::prefix("/prefix/{v1}"), 2);
|
||||
|
||||
let mut resource = Path::new("/prefix/1/second/2");
|
||||
assert_eq!(tree.find(&mut resource), Some(1));
|
||||
assert_eq!(&resource["v1"], "1");
|
||||
assert_eq!(&resource["v2"], "2");
|
||||
|
||||
let mut resource = Path::new("/prefix/1/second");
|
||||
assert_eq!(tree.find(&mut resource), Some(2));
|
||||
assert_eq!(&resource["v1"], "1");
|
||||
assert_eq!(tree.find(&mut Path::new("/prefix/1")), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -361,7 +361,6 @@ impl Tree {
|
|||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
// check segment match
|
||||
let is_match = match key[0] {
|
||||
Segment::Static(ref pattern) => {
|
||||
|
@ -471,6 +470,32 @@ impl Tree {
|
|||
}
|
||||
Value::Prefix(v) => {
|
||||
if p == PathState::Slesh || p == PathState::Tail {
|
||||
if !self.children.is_empty() {
|
||||
let p = if path.len() != 1 {
|
||||
&path[1..]
|
||||
} else {
|
||||
path
|
||||
};
|
||||
if let Some(res) = self
|
||||
.children
|
||||
.iter()
|
||||
.map(|x| {
|
||||
x.find_inner2(
|
||||
p,
|
||||
resource,
|
||||
check,
|
||||
skip,
|
||||
segments,
|
||||
insensitive,
|
||||
base_skip,
|
||||
)
|
||||
})
|
||||
.filter_map(|x| x)
|
||||
.next()
|
||||
{
|
||||
return Some(res);
|
||||
}
|
||||
}
|
||||
*v
|
||||
} else {
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue