Skip to content

Commit

Permalink
Add more tests for empty path segment capture
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswuollett committed Jul 28, 2023
1 parent 2fa08ca commit 1f4c0a3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions axum/src/extract/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>| 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(
Expand All @@ -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");

Expand Down

0 comments on commit 1f4c0a3

Please sign in to comment.