mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
fix nested resource map registration #915
This commit is contained in:
parent
d7ec241fd0
commit
d293ae2a69
@ -20,6 +20,10 @@
|
||||
|
||||
* Re-apply patch from #637 #894
|
||||
|
||||
### Fixed
|
||||
|
||||
* HttpRequest::url_for is broken with nested scopes #915
|
||||
|
||||
|
||||
## [1.0.0] - 2019-06-05
|
||||
|
||||
|
@ -38,7 +38,8 @@ impl ResourceMap {
|
||||
pub(crate) fn finish(&self, current: Rc<ResourceMap>) {
|
||||
for (_, nested) in &self.patterns {
|
||||
if let Some(ref nested) = nested {
|
||||
*nested.parent.borrow_mut() = Some(current.clone())
|
||||
*nested.parent.borrow_mut() = Some(current.clone());
|
||||
nested.finish(nested.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
src/scope.rs
20
src/scope.rs
@ -1135,4 +1135,24 @@ mod tests {
|
||||
let body = read_body(resp);
|
||||
assert_eq!(body, &b"https://youtube.com/watch/xxxxxx"[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_url_for_nested() {
|
||||
let mut srv = init_service(App::new().service(web::scope("/a").service(
|
||||
web::scope("/b").service(web::resource("/c/{stuff}").name("c").route(
|
||||
web::get().to(|req: HttpRequest| {
|
||||
HttpResponse::Ok()
|
||||
.body(format!("{}", req.url_for("c", &["12345"]).unwrap()))
|
||||
}),
|
||||
)),
|
||||
)));
|
||||
let req = TestRequest::with_uri("/a/b/c/test").to_request();
|
||||
let resp = call_service(&mut srv, req);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let body = read_body(resp);
|
||||
assert_eq!(
|
||||
body,
|
||||
Bytes::from_static(b"http://localhost:8080/a/b/c/12345")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user