mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 10:42:55 +01:00
Fix match_pattern() returning None for scope with resource of empty path (#1798)
* fix match_pattern function not returning pattern where scope has resource of path "" * remove print in test * make comparison on existing else if block * add fix to changelog
This commit is contained in:
parent
7981e0068a
commit
1f70ef155d
@ -4,6 +4,9 @@
|
||||
### Fixed
|
||||
* Ensure `actix-http` dependency uses same `serde_urlencoded`.
|
||||
* Removed an occasional `unwrap` on `None` panic in `NormalizePathNormalization`.
|
||||
* Fix match_pattern() returning None for scope with resource of empty path. [#1798]
|
||||
|
||||
[#1798]: https://github.com/actix/actix-web/pull/1798
|
||||
|
||||
|
||||
## 3.3.0 - 2020-11-25
|
||||
|
@ -675,4 +675,40 @@ mod tests {
|
||||
let res = call_service(&mut srv, req).await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn extract_path_pattern_complex() {
|
||||
let mut srv = init_service(
|
||||
App::new()
|
||||
.service(web::scope("/user").service(web::scope("/{id}").service(
|
||||
web::resource("").to(move |req: HttpRequest| {
|
||||
assert_eq!(req.match_pattern(), Some("/user/{id}".to_owned()));
|
||||
|
||||
HttpResponse::Ok().finish()
|
||||
}),
|
||||
)))
|
||||
.service(web::resource("/").to(move |req: HttpRequest| {
|
||||
assert_eq!(req.match_pattern(), Some("/".to_owned()));
|
||||
|
||||
HttpResponse::Ok().finish()
|
||||
}))
|
||||
.default_service(web::to(move |req: HttpRequest| {
|
||||
assert!(req.match_pattern().is_none());
|
||||
HttpResponse::Ok().finish()
|
||||
})),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = TestRequest::get().uri("/user/test").to_request();
|
||||
let res = call_service(&mut srv, req).await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
let req = TestRequest::get().uri("/").to_request();
|
||||
let res = call_service(&mut srv, req).await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
let req = TestRequest::get().uri("/not-exist").to_request();
|
||||
let res = call_service(&mut srv, req).await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ impl ResourceMap {
|
||||
if let Some(plen) = pattern.is_prefix_match(path) {
|
||||
return rmap.has_resource(&path[plen..]);
|
||||
}
|
||||
} else if pattern.is_match(path) {
|
||||
} else if pattern.is_match(path) || pattern.pattern() == "" && path == "/" {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user