diff --git a/axum/src/extract/path/mod.rs b/axum/src/extract/path/mod.rs index 1d9a8c0eea..dd9accccf2 100644 --- a/axum/src/extract/path/mod.rs +++ b/axum/src/extract/path/mod.rs @@ -657,6 +657,25 @@ mod tests { assert_eq!(res.text().await, ""); } + #[crate::test] + async fn captures_match_empty_inner_segments_near_end() { + let app = Router::new().route( + "/method/:key/", + get(|Path(param): Path| async move { param.to_string() }), + ); + + let client = TestClient::new(app); + + let res = client.get("/method/abc").send().await; + assert_eq!(res.status(), StatusCode::NOT_FOUND); + + let res = client.get("/method/abc/").send().await; + assert_eq!(res.text().await, "abc"); + + let res = client.get("/method//").send().await; + assert_eq!(res.text().await, ""); + } + #[crate::test] async fn captures_match_empty_trailing_segment() { let app = Router::new().route( @@ -666,6 +685,9 @@ mod tests { let client = TestClient::new(app); + let res = client.get("/method/abc/").send().await; + assert_eq!(res.status(), StatusCode::NOT_FOUND); + let res = client.get("/method/abc").send().await; assert_eq!(res.text().await, "abc");