dotnet / dotnet/aspnetcore

Invalid pathBase in RedirectRule

Open
#8,310 1 comment 0 reactions 0 assignees View on GitHub
area-middleware bug
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Describe the bug
I found a bug about pathBase in RedirectRule class. (namespace: Microsoft.AspNetCore.Rewrite.Internal)
If I use pathBase in my project and set an absolute URL to the replacement parameter, an error occurs.

### To Reproduce
Steps to reproduce the behavior:
1. Using this version of ASP.NET Core App '2.2.0'
2. Run this code

public async Task CheckRewritePath(string pathBase, string regex, string replacement, string expected)
{
// Arrange
var options = new RewriteOptions().Add(new RedirectRule(regex, replacement, StatusCodes.Status302Found));
var builder = new WebHostBuilder().Configure(app => { app.UsePathBase(pathBase); app.UseRewriter(options); });
var server = new TestServer(builder);

// Act
var response = await server.CreateClient().GetAsync(pathBase + "/" + regex);

// Assert
Assert.Equal(expected, response.Headers.Location.OriginalString);
}
3. With these arguments
[Theory]
[InlineData("/Test", "RedirectRule1", "https://localhost/Test/Home/Index", "https://localhost/Test/Home/Index")]
[InlineData("/Test", "RedirectRule2", "/Home/Index", "/Test/Home/Index")]
[InlineData("/Test", "RedirectRule3", "Home/Index", "/Test/Home/Index")]
4. See error
respons.Headers.Location.OrinalString returned /Testhttps://localhost/Test/RedirectRule

### Expected behavior
I expected to redirect absolute URL.
ex) https://localhost/Test/Home/Index

### Screenshots
![image](https://user-images.githubusercontent.com/8253350/53999829-475ac700-4188-11e9-97fd-094195e18161.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.