Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpRequest::url_for is broken with nested scopes #915

Closed
Voxelot opened this issue Jun 13, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Voxelot
Copy link

commented Jun 13, 2019

Summary
While it appears the fix for #429 works when there is one scope enclosing the route, it doesn't traverse all the way to the root scope.

Example

extern crate actix_web;

use actix_web::*;
use bytes::Bytes;
use crate::http::{StatusCode};
use crate::test::{
    call_service, init_service, read_body, TestRequest,
};


#[test]
fn test_external_resource() {
    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"));
}

Expected Output

http://localhost:8080/a/b/c/12345

Actual Output

http://localhost:8080/b/c/12345

fafhrd91 added a commit that referenced this issue Jun 15, 2019

@fafhrd91

This comment has been minimized.

Copy link
Member

commented Jun 15, 2019

fixed in master

@fafhrd91 fafhrd91 closed this Jun 15, 2019

@Voxelot

This comment has been minimized.

Copy link
Author

commented Jun 17, 2019

Thanks for the quick release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.