Missing trailing backslash after pathBase when Path is empty
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Found a bug that backslash is missing after PathBase, if Path is empty.
### Expected Behavior
If pathBase is non empty and Path is empty, then add a trailing backslash after pathBase in the route url.
Actual url: /twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.co**m?**_type=Patient&_count=500&ct=er97f5lRTbShgbGOqaGBuaGFqbGJiZmhibmRobGZUSwAAAD%2F%2Fw%3D%3D
Expected url: /twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.com/?_type=Patient&_count=500&ct=er97f5lRTbShgbGOqaGBuaGFqbGJiZmhibmRobGZUSwAAAD%2F%2Fw%3D%3D
The issue is here https://github.com/dotnet/aspnetcore/blob/481e472ea22a53fe96f11ba001c2dd4fbdc59ed5/src/Http/Http.Extensions/src/UriHelper.cs#L36
### Steps To Reproduce
- Search URl: https://localhost:44349/twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.com/?_type=Patient&_count=500
_Host: localhost:44349, basePath: /twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.com, Path: Empty, Query parameter: _type=Patient&_count=500__
- In our implementation, we are calling AspnetCore UrlHelper.RouteUrl() to get the route url
- Further debugging, LinkGeneratorExtensions.GetPathByRouteValues -> GetPathByAddress() -> DefaultLinkGenerator.GetPathByEndpoints() -> TryProcessTemplate() fetches _pathBase_ as ""/twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.com" and _Path_ as ""(empty)
- UriHelper.BuildRelative constructs the url as below
/twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.co**m?**_type=Patient&_count=500&ct=er97f5lRTbShgbGOqaGBuaGFqbGJiZmhibmRobGZUSwAAAD%2F%2Fw%3D%3D
Expected url: /twci369916wu2hsws-twci369916wu2hsws.fhir.mshapis.com/?_type=Patient&_count=500&ct=er97f5lRTbShgbGOqaGBuaGFqbGJiZmhibmRobGZUSwAAAD%2F%2Fw%3D%3D
### Exceptions (if any)
_No response_
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Research direction
Start in src/Http/Http.Extensions/src/UriHelper.cs at the referenced line and trace how UriHelper.BuildRelative combines PathBase, Path, and the query string. Reproduce the empty-Path case through the reported RouteUrl flow, then verify that a non-empty PathBase produces the expected trailing slash before the query.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100