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:
But when run on TestHost, encoding forward slash really makes no difference:
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
I'll move this bug over to HttpAbstrations. There should be a better way to unescape everything but %2F.
Backlogging this issue.
I'm about to change code a bit, so please use permalinks instead:
https://github.com/PawelTroka/Computator.NET/blob/c1061e722f366c59fa2cfa5047dcccba6a8267df/Computator.NET.WebApi.IntegrationTests/CalculateApiTests.cs#L49
https://github.com/PawelTroka/Computator.NET/blob/c1061e722f366c59fa2cfa5047dcccba6a8267df/Computator.NET.WebApi/Controllers/CalculateController.cs#L32
This issue was moved to dotnet/aspnetcore#2696