From 2301083edc2800e5dff7be31b643e5baca213efa Mon Sep 17 00:00:00 2001 From: Valerio Ageno <51341197+Valerioageno@users.noreply.github.com> Date: Sat, 15 Mar 2025 18:16:54 +0100 Subject: [PATCH] fix: allow 'index' keyword in routes name (#647) --- crates/tuono/src/route.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/tuono/src/route.rs b/crates/tuono/src/route.rs index 54268054..6733c3f9 100644 --- a/crates/tuono/src/route.rs +++ b/crates/tuono/src/route.rs @@ -28,7 +28,11 @@ impl AxumInfo { let mut module = route.path.chars(); module.next(); - let axum_route = route.path.replace("/index", ""); + let axum_route = if route.path.ends_with("/index") { + route.path.replace("/index", "") + } else { + route.path.clone() + }; let module_import = module .as_str() @@ -302,6 +306,18 @@ mod tests { .for_each(|route| assert_eq!(has_dynamic_path(route.0), route.1)); } + #[test] + fn should_allow_index_in_route_name() { + let index_route = AxumInfo::new(&Route::new("/index".to_string())); + let index_page_route = AxumInfo::new(&Route::new("/index-page".to_string())); + + assert_eq!(index_route.axum_route, "/"); + assert_eq!(index_route.module_import, "index"); + + assert_eq!(index_page_route.axum_route, "/index-page"); + assert_eq!(index_page_route.module_import, "index_hyphen_page"); + } + #[test] fn should_correctly_create_the_axum_infos() { let info = AxumInfo::new(&Route::new("/index".to_string()));