diff --git a/integrations/actix/tests/extract_routes.rs b/integrations/actix/tests/extract_routes.rs index eef79759b4..67765b187e 100644 --- a/integrations/actix/tests/extract_routes.rs +++ b/integrations/actix/tests/extract_routes.rs @@ -107,7 +107,6 @@ fn test_redirect_app() { "/bar", "/bar/", "/baz/*any", - "/baz/*any/", // !!! TODO "/baz/:id", "/baz/:id/", "/baz/:name", @@ -129,7 +128,6 @@ fn test_redirect_app() { "/baz/{name}", "/baz/{name}/", "/baz/{tail:.*}", - "/baz/{tail:.*}", // !!! TODO "/foo", "/foo/", ], diff --git a/router/src/components/routes.rs b/router/src/components/routes.rs index 5bc7df98da..d11c43f2b1 100644 --- a/router/src/components/routes.rs +++ b/router/src/components/routes.rs @@ -691,36 +691,37 @@ fn create_routes( for original_path in expand_optionals(&route_def.path) { let mut path = join_paths(base, &original_path).to_string(); trailing_slash.normalize_route_path(&mut path); - let mut is_wildcard = false; let pattern = if is_leaf { path } else if let Some((path, _splat)) = path.split_once("/*") { - is_wildcard = true; path.to_string() } else { path }; - acc.push(RouteData { + + let route_data = RouteData { key: route_def.clone(), id: route_def.id, matcher: Matcher::new_with_partial(&pattern, !is_leaf), pattern, original_path: original_path.into_owned(), - }); + }; - if is_wildcard { + if route_data.matcher.is_wildcard() { // already handles trailing_slash - // TODO: confirm/test } else if let Some(redirect_route) = redirect_route_for(route_def) { let pattern = &redirect_route.path; - acc.push(RouteData { + let redirect_route_data = RouteData { id: redirect_route.id, - matcher: Matcher::new_with_partial(&pattern, !is_leaf), // TODO: 👀 + matcher: Matcher::new_with_partial(&pattern, !is_leaf), pattern: pattern.to_owned(), original_path: pattern.to_owned(), key: redirect_route, - }); + }; + acc.push(redirect_route_data); } + + acc.push(route_data); } acc } diff --git a/router/src/matching/matcher.rs b/router/src/matching/matcher.rs index eace3813ab..3c0d1a9986 100644 --- a/router/src/matching/matcher.rs +++ b/router/src/matching/matcher.rs @@ -97,6 +97,11 @@ impl Matcher { Some(PathMatch { path, params }) } } + + #[doc(hidden)] + pub(crate) fn is_wildcard(&self) -> bool { + self.splat.is_some() + } } fn get_segments(pattern: &str) -> Vec<&str> { diff --git a/router/tests/extract_routes.rs b/router/tests/extract_routes.rs index 2bd8b11e59..393c72e244 100644 --- a/router/tests/extract_routes.rs +++ b/router/tests/extract_routes.rs @@ -82,7 +82,6 @@ fn test_generated_routes_redirect() { "/bar", "/bar/", "/baz/*any", - "/baz/*any/", // !!! TODO "/baz/:id", "/baz/:id/", "/baz/:name",