dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.59k stars 10.06k forks source link

TemplateBinder strip trailing slash #57988

Open benjaminpetit opened 2 months ago

benjaminpetit commented 2 months ago

Is there an existing issue for this?

Describe the bug

When the route is defined as Test/{val1} and val1 is empty, the result is Test (without trailing slash).

Trailing slash do matter in some cases.

Expected Behavior

When the route is defined as Test/{val1} and val1 is empty, the result is Test/ (with trailing slash).

Steps To Reproduce

https://github.com/dotnet/aspnetcore/blob/73c82c6a41b08b65753461c3273d4990cd5c747e/src/Http/Routing/test/UnitTests/Template/TemplateBinderTests.cs#L60

Exceptions (if any)

No response

.NET Version

8

Anything else?

Related issue: https://github.com/microsoft/reverse-proxy/issues/2531

HugoVG commented 2 months ago

currently experiencing this bug with YARP as well

nicolas-girod commented 1 week ago

I have the same issue except it's not with an empty value. The pattern is /bcf/{bcf_version}/projects/ with bcf_version equal to 3.0 the trailing slash is also removed. However, /bcf/{bcf_version}/{**endpoint} with the catch-all containing projects/ works as intended.