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
11 changes: 7 additions & 4 deletions src/Http/Http.Extensions/src/UriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ public static string BuildAbsolute(
queryText.Length +
fragmentText.Length;

if (string.IsNullOrEmpty(pathBaseText) && string.IsNullOrEmpty(pathText))
if (string.IsNullOrEmpty(pathText))
{
pathText = "/";
length++;
if (string.IsNullOrEmpty(pathBaseText))
{
pathText = "/";
length++;
}
}
else if (pathBaseText.Length > 0 && pathBaseText[^1] == '/')
else if (pathBaseText.EndsWith('/'))
{
// If the path string has a trailing slash and the other string has a leading slash, we need
// to trim one of them.
Expand Down
1 change: 1 addition & 0 deletions src/Http/Http.Extensions/test/UriHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void EncodeFullUrl()
[InlineData("http", "example.com", "", "/foo", "?bar=1", "#col=2", "http://example.com/foo?bar=1#col=2")]
[InlineData("http", "example.com", "/base", "/foo", "?bar=1", "#col=2", "http://example.com/base/foo?bar=1#col=2")]
[InlineData("http", "example.com", "/base/", "/foo", "?bar=1", "#col=2", "http://example.com/base/foo?bar=1#col=2")]
[InlineData("http", "example.com", "/base/", "", "?bar=1", "#col=2", "http://example.com/base/?bar=1#col=2")]
[InlineData("http", "example.com", "", "", "?bar=1", "#col=2", "http://example.com/?bar=1#col=2")]
[InlineData("http", "example.com", "", "", "", "#frag?stillfrag/stillfrag", "http://example.com/#frag?stillfrag/stillfrag")]
[InlineData("http", "example.com", "", "", "?q/stillq", "#frag?stillfrag/stillfrag", "http://example.com/?q/stillq#frag?stillfrag/stillfrag")]
Expand Down