fix: allow 'index' keyword in routes name (#647)

This commit is contained in:
Valerio Ageno
2025-03-15 18:16:54 +01:00
committed by GitHub
parent 1c45b29ed1
commit 2301083edc
+17 -1
View File
@@ -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()));