From 439f4d63858fe95256f72efaefecbe17243fdb24 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Thu, 18 Jun 2020 11:21:12 -0700 Subject: [PATCH] use route-recognizer 0.2 --- Cargo.toml | 2 +- tests/wildcard.rs | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eca1a776a..e9e474763 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,9 +38,9 @@ async-std = { version = "1.6.0", features = ["unstable"] } femme = "2.0.1" http-types = "2.0.1" kv-log-macro = "1.0.4" -route-recognizer = "0.1.13" serde = "1.0.102" serde_json = "1.0.41" +route-recognizer = "0.2.0" [dev-dependencies] async-std = { version = "1.6.0", features = ["unstable", "attributes"] } diff --git a/tests/wildcard.rs b/tests/wildcard.rs index b0eafbc34..0821d87fb 100644 --- a/tests/wildcard.rs +++ b/tests/wildcard.rs @@ -25,13 +25,6 @@ async fn echo_path(req: Request<()>) -> Result { } } -async fn echo_empty(req: Request<()>) -> Result { - match req.param::("") { - Ok(path) => Ok(path), - Err(err) => Err(tide::Error::new(StatusCode::BadRequest, err)), - } -} - #[async_std::test] async fn wildcard() { let mut app = tide::Server::new(); @@ -223,13 +216,29 @@ async fn nameless_internal_wildcard() { #[async_std::test] async fn nameless_internal_wildcard2() { let mut app = tide::new(); - app.at("/echo/:/:path").get(echo_empty); + app.at("/echo/:/:path").get(|req: Request<()>| async move { + assert_eq!(req.param::("path")?, "two"); + Ok("") + }); let req = http::Request::new( Method::Get, Url::parse("http://localhost/echo/one/two").unwrap(), ); - let mut res: http::Response = app.respond(req).await.unwrap(); - assert_eq!(res.status(), StatusCode::Ok); - assert_eq!(&res.body_string().await.unwrap(), "one"); + let _: tide::Response = app.respond(req).await.unwrap(); +} + +#[async_std::test] +async fn ambiguous_router_wildcard_vs_star() { + let mut app = tide::new(); + app.at("/:one/:two").get(|_| async { Ok("one/two") }); + app.at("/posts/*").get(|_| async { Ok("posts/*") }); + let req = http::Request::new( + Method::Get, + Url::parse("http://localhost/posts/10").unwrap(), + ); + + let mut response: http_types::Response = app.respond(req).await.unwrap(); + let body_string = response.body_string().await.unwrap(); + assert_eq!(body_string, "posts/*"); }