Skip to content

Commit 1b04916

Browse files
authored
Merge pull request #19 from adriangb/handle-empty-paths
feat: handle empty paths
2 parents 1ccee7e + d8be816 commit 1b04916

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
- **Fast**: See benchmark
3131

32-
- **Micro**: The [src/lib.rs](src/lib.rs) file is ~407 lines of code (Includes comments)
32+
- **Micro**: The [src/lib.rs](src/lib.rs) file is ~405 lines of code (Includes comments)
3333

3434
- **Flexible**:
3535

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<T> Node<T> {
193193
NodeKind::Static(ref s) => {
194194
let l = loc(s, p);
195195

196-
if l == 0 || l < s.len() {
196+
if l < s.len() {
197197
None
198198
} else if l == s.len() && l == p.len() {
199199
Some(
@@ -297,7 +297,7 @@ impl<T> PathTree<T> {
297297
#[inline]
298298
pub fn new() -> Self {
299299
Self {
300-
root: Node::new(NodeKind::Static("/".to_owned())),
300+
root: Node::new(NodeKind::Static("".to_owned())),
301301
params: 0,
302302
}
303303
}
@@ -310,8 +310,6 @@ impl<T> PathTree<T> {
310310

311311
let mut most = 0;
312312

313-
path = path.trim_start_matches('/');
314-
315313
if path.is_empty() {
316314
node.data.replace(data);
317315
return self;

tests/basic.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use rand::seq::SliceRandom;
55
fn new_tree() {
66
let mut tree: PathTree<usize> = PathTree::default();
77

8-
const ROUTES: [&str; 13] = [
8+
const ROUTES: [&str; 14] = [
9+
"",
910
"/",
1011
"/users",
1112
"/users/:id",
@@ -21,7 +22,8 @@ fn new_tree() {
2122
"/users/repos/*any",
2223
];
2324

24-
const VALID_URLS: [&str; 13] = [
25+
const VALID_URLS: [&str; 14] = [
26+
"",
2527
"/",
2628
"/users",
2729
"/users/fundon",
@@ -38,6 +40,7 @@ fn new_tree() {
3840
];
3941

4042
let valid_res = vec![
43+
vec![],
4144
vec![],
4245
vec![],
4346
vec![("id", "fundon")],

0 commit comments

Comments
 (0)