mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 04:47:39 +03:00
partial matches keep garbage in segments
This commit is contained in:
parent
cfaa2cc3ca
commit
8d29fac124
6 changed files with 57 additions and 6 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [0.4.1] - 2021-02-26
|
||||
|
||||
* Fix: partial matches keep garbage in segments
|
||||
|
||||
## [0.4.0] - 2021-02-23
|
||||
|
||||
* Upgrade to bytestring 1.0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-router"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "Path router"
|
||||
keywords = ["ntex"]
|
||||
|
|
|
@ -9,7 +9,7 @@ mod router;
|
|||
mod tree;
|
||||
|
||||
pub use self::de::PathDeserializer;
|
||||
pub use self::path::Path;
|
||||
pub use self::path::{Path, PathIter};
|
||||
pub use self::resource::ResourceDef;
|
||||
pub use self::router::{ResourceInfo, Router, RouterBuilder};
|
||||
|
||||
|
|
|
@ -170,6 +170,7 @@ impl<T: ResourcePath> Path<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Iterator to items in parameter container
|
||||
#[derive(Debug)]
|
||||
pub struct PathIter<'a, T> {
|
||||
idx: usize,
|
||||
|
|
|
@ -992,4 +992,18 @@ mod tests {
|
|||
assert_eq!(tree.find(&mut Path::new("/test")), Some(4));
|
||||
assert_eq!(tree.find(&mut Path::new("/test/index.html")), Some(4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_some_match() {
|
||||
let mut tree = Tree::new(&ResourceDef::new("/p/{tp}/{id}/{r}"), 1);
|
||||
tree.insert(&ResourceDef::new("/p/ih/{tp}/d/{id}/sid/{r}/r/{s}"), 3);
|
||||
|
||||
let mut p = Path::new("/p/ih/def/d/abc/sid/5bddc58f/r/srv");
|
||||
assert_eq!(tree.find(&mut p), Some(3));
|
||||
assert_eq!(p.get("tp"), Some("def"));
|
||||
assert_eq!(p.get("id"), Some("abc"));
|
||||
assert_eq!(p.get("r"), Some("5bddc58f"));
|
||||
assert_eq!(p.get("s"), Some("srv"));
|
||||
assert_eq!(p.len(), 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ impl Tree {
|
|||
.children
|
||||
.iter()
|
||||
.map(|x| {
|
||||
x.find_inner2(
|
||||
x.find_inner_wrapped(
|
||||
path,
|
||||
resource,
|
||||
check,
|
||||
|
@ -289,7 +289,7 @@ impl Tree {
|
|||
path
|
||||
};
|
||||
|
||||
if let Some((val, skip)) = self.find_inner2(
|
||||
if let Some((val, skip)) = self.find_inner_wrapped(
|
||||
path,
|
||||
resource,
|
||||
check,
|
||||
|
@ -307,6 +307,38 @@ impl Tree {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn find_inner_wrapped<T, R, F>(
|
||||
&self,
|
||||
path: &str,
|
||||
resource: &R,
|
||||
check: &F,
|
||||
skip: usize,
|
||||
segments: &mut Vec<(&'static str, PathItem)>,
|
||||
insensitive: bool,
|
||||
base_skip: isize,
|
||||
) -> Option<(usize, usize)>
|
||||
where
|
||||
T: ResourcePath,
|
||||
R: Resource<T>,
|
||||
F: Fn(usize, &R) -> bool,
|
||||
{
|
||||
let len = segments.len();
|
||||
let res = self.find_inner2(
|
||||
path,
|
||||
resource,
|
||||
check,
|
||||
skip,
|
||||
segments,
|
||||
insensitive,
|
||||
base_skip,
|
||||
);
|
||||
if res.is_none() {
|
||||
segments.truncate(len);
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn find_inner2<T, R, F>(
|
||||
&self,
|
||||
|
@ -477,7 +509,7 @@ impl Tree {
|
|||
.children
|
||||
.iter()
|
||||
.map(|x| {
|
||||
x.find_inner2(
|
||||
x.find_inner_wrapped(
|
||||
p,
|
||||
resource,
|
||||
check,
|
||||
|
@ -517,7 +549,7 @@ impl Tree {
|
|||
.children
|
||||
.iter()
|
||||
.map(|x| {
|
||||
x.find_inner2(
|
||||
x.find_inner_wrapped(
|
||||
path,
|
||||
resource,
|
||||
check,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue