aspnet / HttpAbstractions

[Archived] HTTP abstractions such as HttpRequest, HttpResponse, and HttpContext, as well as common web utilities. Project moved to https://github.com/aspnet/AspNetCore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PathString.FromUriComponent encoding forward slash makes no difference

Tratcher opened this issue · comments

From @PawelTroka on August 2, 2017 10:17

It was already shortly discussed in aspnet/Mvc#2826 where @davidfowl suggested that the issue I am encountering is only happening on TestHost. And yes, he is right - it works correctly when hosted and invoked through web browser or any web client for that matter.

It is failing however in my integration tests where I am using Microsoft.AspNetCore.TestHost v1.1.2 and Microsoft.AspNetCore.WebUtilities v1.1.2. Please notice that my WebApi and WebApi.IntegrationTests are AspNetCore 1.1 but are targeting net461 (due to some of my libraries not yet ported).

Repro:
Unit test:
https://github.com/PawelTroka/Computator.NET/blob/master/Computator.NET.WebApi.IntegrationTests/CalculateApiTests.cs#L49
Should go through route:
real/{equation}/{x} from method:
https://github.com/PawelTroka/Computator.NET/blob/master/Computator.NET.WebApi/Controllers/CalculateController.cs#L32
But because encoding forward slash makes no difference it is going through different route:
real/{equation}/{x}/{customFunctionsCode} from the same method

In images:
When run through browser everything is ok:
image
image

But when run on TestHost, encoding forward slash really makes no difference:
image

Copied from original issue: aspnet/Hosting#1155

Here's the code causing the un-escaping:
https://github.com/aspnet/Hosting/blob/44272ca2ba7082dd31c3de0ef9d5b5a400db1b78/src/Microsoft.AspNetCore.TestHost/ClientHandler.cs#L140

return new PathString("/" + uri.GetComponents(UriComponents.Path, UriFormat.Unescaped));

I'll move this bug over to HttpAbstrations. There should be a better way to unescape everything but %2F.

Backlogging this issue.

This issue was moved to dotnet/aspnetcore#2696