@@ -25,13 +25,6 @@ async fn echo_path(req: Request<()>) -> Result<String, tide::Error> {
2525 }
2626}
2727
28- async fn echo_empty ( req : Request < ( ) > ) -> Result < String , tide:: Error > {
29- match req. param :: < String > ( "" ) {
30- Ok ( path) => Ok ( path) ,
31- Err ( err) => Err ( tide:: Error :: new ( StatusCode :: BadRequest , err) ) ,
32- }
33- }
34-
3528#[ async_std:: test]
3629async fn wildcard ( ) {
3730 let mut app = tide:: Server :: new ( ) ;
@@ -223,13 +216,29 @@ async fn nameless_internal_wildcard() {
223216#[ async_std:: test]
224217async fn nameless_internal_wildcard2 ( ) {
225218 let mut app = tide:: new ( ) ;
226- app. at ( "/echo/:/:path" ) . get ( echo_empty) ;
219+ app. at ( "/echo/:/:path" ) . get ( |req : Request < ( ) > | async move {
220+ assert_eq ! ( req. param:: <String >( "path" ) ?, "two" ) ;
221+ Ok ( "" )
222+ } ) ;
227223
228224 let req = http:: Request :: new (
229225 Method :: Get ,
230226 Url :: parse ( "http://localhost/echo/one/two" ) . unwrap ( ) ,
231227 ) ;
232- let mut res: http:: Response = app. respond ( req) . await . unwrap ( ) ;
233- assert_eq ! ( res. status( ) , StatusCode :: Ok ) ;
234- assert_eq ! ( & res. body_string( ) . await . unwrap( ) , "one" ) ;
228+ let _: tide:: Response = app. respond ( req) . await . unwrap ( ) ;
229+ }
230+
231+ #[ async_std:: test]
232+ async fn ambiguous_router_wildcard_vs_star ( ) {
233+ let mut app = tide:: new ( ) ;
234+ app. at ( "/:one/:two" ) . get ( |_| async { Ok ( "one/two" ) } ) ;
235+ app. at ( "/posts/*" ) . get ( |_| async { Ok ( "posts/*" ) } ) ;
236+ let req = http:: Request :: new (
237+ Method :: Get ,
238+ Url :: parse ( "http://localhost/posts/10" ) . unwrap ( ) ,
239+ ) ;
240+
241+ let mut response: http_types:: Response = app. respond ( req) . await . unwrap ( ) ;
242+ let body_string = response. body_string ( ) . await . unwrap ( ) ;
243+ assert_eq ! ( body_string, "posts/*" ) ;
235244}
0 commit comments