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

Autoredirect not working correctly for paths containing query parameters #586

Closed
AeonLucid opened this issue Dec 12, 2020 · 2 comments
Closed
Labels

Comments

@AeonLucid
Copy link
Contributor

AeonLucid commented Dec 12, 2020

Here is a test reproducing the issue, this is a slightly modified version of RedirectTests.can_auto_redirect.

[Test]
public async Task can_auto_redirect() {
    HttpTest
        .RespondWith("", 302, new { Location = "http://redir.com/foo" })
        .RespondWith("", 302, new { Location = "/redir2" })
        .RespondWith("", 302, new { Location = "redir3" })
        .RespondWith("", 302, new { Location = "/redir2?a=b&c=d" })
        .RespondWith("done!");

    var resp = await "http://start.com".PostStringAsync("foo!").ReceiveString();

    Assert.AreEqual("done!", resp);
    HttpTest.ShouldHaveMadeACall().Times(5);
    HttpTest.ShouldHaveCalled("http://start.com").WithVerb(HttpMethod.Post).WithRequestBody("foo!")
        .With(call => call.RedirectedFrom == null);
    HttpTest.ShouldHaveCalled("http://redir.com/foo").WithVerb(HttpMethod.Get).WithRequestBody("")
        .With(call => call.RedirectedFrom.Request.Url.ToString() == "http://start.com");
    HttpTest.ShouldHaveCalled("http://redir.com/redir2").WithVerb(HttpMethod.Get).WithRequestBody("")
        .With(call => call.RedirectedFrom.Request.Url.ToString() == "http://redir.com/foo");
    HttpTest.ShouldHaveCalled("http://redir.com/redir2/redir3").WithVerb(HttpMethod.Get).WithRequestBody("")
        .With(call => call.RedirectedFrom.Request.Url.ToString() == "http://redir.com/redir2");
    HttpTest.ShouldHaveCalled("http://redir.com/redir2?a=b&c=d").WithVerb(HttpMethod.Get).WithRequestBody("")
        .With(call => call.RedirectedFrom.Request.Url.ToString() == "http://redir.com/redir2/redir3");
}

If we look into the CallLog, it is obvious why the test did not succeed.

image

In a real world application, this causes a 404 because it think the query parameters are part of the route.

@AeonLucid AeonLucid added the bug label Dec 12, 2020
@AeonLucid AeonLucid changed the title Autoredirect not working correctly for paths containg query parameters Autoredirect not working correctly for paths containing query parameters Dec 12, 2020
@tmenier
Copy link
Owner

tmenier commented Dec 14, 2020

This is legit. Thanks for reporting.

@tmenier
Copy link
Owner

tmenier commented Dec 14, 2020

Fixed & released in 3.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants