Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Task Invoke(HttpContext context)
return _next(context);
}

private async Task InvokeCore(HttpContext context, string matchedPath, string remainingPath)
private async Task InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
{
var path = context.Request.Path;
var pathBase = context.Request.PathBase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -26,7 +26,7 @@ public static IApplicationBuilder UsePathBase(this IApplicationBuilder app, Path
}

// Strip trailing slashes
pathBase = pathBase.Value?.TrimEnd('/');
pathBase = new PathString(pathBase.Value?.TrimEnd('/'));
if (!pathBase.HasValue)
{
return app;
Expand All @@ -35,4 +35,4 @@ public static IApplicationBuilder UsePathBase(this IApplicationBuilder app, Path
return app.UseMiddleware<UsePathBaseMiddleware>(pathBase);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Task Invoke(HttpContext context)
return _next(context);
}

private async Task InvokeCore(HttpContext context, string matchedPath, string remainingPath)
private async Task InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
{
var originalPath = context.Request.Path;
var originalPathBase = context.Request.PathBase;
Expand Down
21 changes: 12 additions & 9 deletions src/Http/Http.Abstractions/test/MapPathMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,27 @@ public void NullArguments_ArgumentNullException()
}

[Theory]
[InlineData("/foo", "", "/foo")]
[InlineData("/foo", "", "/foo/")]
[InlineData("/foo", "/Bar", "/foo")]
[InlineData("/foo", "/Bar", "/foo/cho")]
[InlineData("/foo", "/Bar", "/foo/cho/")]
[InlineData("/foo/cho", "/Bar", "/foo/cho")]
[InlineData("/foo/cho", "/Bar", "/foo/cho/do")]
public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath)
[InlineData("/foo", "", "/foo", "/foo", "")]
[InlineData("/foo", "", "/foo/", "/foo", "/")]
[InlineData("/foo", "/Bar", "/foo", "/Bar/foo", "")]
[InlineData("/foo", "/Bar", "/foo/cho", "/Bar/foo", "/cho")]
[InlineData("/foo", "/Bar", "/foo/cho/", "/Bar/foo", "/cho/")]
[InlineData("/foo/cho", "/Bar", "/foo/cho", "/Bar/foo/cho", "")]
[InlineData("/foo/cho", "/Bar", "/foo/cho/do", "/Bar/foo/cho", "/do")]
[InlineData("/foo%42/cho", "/Bar%42", "/foo%42/cho/do%42", "/Bar%42/foo%42/cho", "/do%42")]
public async Task PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath, string expectedPathBase, string expectedPath)
{
HttpContext context = CreateRequest(basePath, requestPath);
var builder = new ApplicationBuilder(serviceProvider: null!);
builder.Map(matchPath, UseSuccess);
builder.Map(new PathString(matchPath), UseSuccess);
var app = builder.Build();
await app.Invoke(context);

Assert.Equal(200, context.Response.StatusCode);
Assert.Equal(basePath, context.Request.PathBase.Value);
Assert.Equal(requestPath, context.Request.Path.Value);
Assert.Equal(expectedPathBase, (string)context.Items["test.PathBase"]!);
Assert.Equal(expectedPath, context.Items["test.Path"]);
}

[Theory]
Expand Down
14 changes: 13 additions & 1 deletion src/Http/Http.Abstractions/test/UsePathBaseExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,23 @@ public Task PathBaseCanHaveUnicodeCharacters(string registeredPathBase, string p
return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath);
}

[Theory]
[InlineData("/b%42", "", "/b%42/something%42", "/b%42", "/something%42")]
[InlineData("/b%42", "", "/B%42/something%42", "/B%42", "/something%42")]
[InlineData("/b%42", "", "/b%42/Something%42", "/b%42", "/Something%42")]
[InlineData("/b%42", "/oldb%42", "/b%42/something%42", "/oldb%42/b%42", "/something%42")]
[InlineData("/b%42", "/oldb%42", "/b%42/Something%42", "/oldb%42/b%42", "/Something%42")]
[InlineData("/b%42", "/oldb%42", "/B%42/something%42", "/oldb%42/B%42", "/something%42")]
public Task PathBaseCanHavePercentCharacters(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath)
{
return TestPathBase(registeredPathBase, pathBase, requestPath, expectedPathBase, expectedPath);
}

private static async Task TestPathBase(string registeredPathBase, string pathBase, string requestPath, string expectedPathBase, string expectedPath)
{
HttpContext requestContext = CreateRequest(pathBase, requestPath);
var builder = CreateBuilder()
.UsePathBase(registeredPathBase);
.UsePathBase(new PathString(registeredPathBase));
builder.Run(context =>
{
context.Items["test.Path"] = context.Request.Path;
Expand Down