Skip to content

Commit

Permalink
Fix / prefix match
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Apr 11, 2020
1 parent 392e1f8 commit bf33882
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ntex-router/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ntex-router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-router"
version = "0.3.2"
version = "0.3.3"
authors = ["Nikolay Kim <[email protected]>"]
description = "Path router"
keywords = ["ntex"]
Expand Down
5 changes: 5 additions & 0 deletions ntex-router/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 11 additions & 1 deletion ntex-router/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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('/') {
Expand Down

0 comments on commit bf33882

Please sign in to comment.