Skip to content

Commit 96c720b

Browse files
committed
Remove unnecessary members
1 parent a04bb67 commit 96c720b

File tree

4 files changed

+38
-499
lines changed

4 files changed

+38
-499
lines changed

src/Components/Components/src/NavigationManager.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,32 @@ public string ToBaseRelativePath(string uri)
240240
throw new ArgumentException(message);
241241
}
242242

243+
internal ReadOnlySpan<char> ToBaseRelativePath(ReadOnlySpan<char> uri)
244+
{
245+
if (MemoryExtensions.StartsWith(uri, _baseUri!.OriginalString.AsSpan(), StringComparison.Ordinal))
246+
{
247+
// The absolute URI must be of the form "{baseUri}something" (where
248+
// baseUri ends with a slash), and from that we return "something"
249+
return uri[_baseUri.OriginalString.Length..];
250+
}
251+
252+
var pathEndIndex = uri.IndexOfAny('#', '?');
253+
var uriPathOnly = pathEndIndex < 0 ? uri : uri[..pathEndIndex];
254+
if (_baseUri.OriginalString.EndsWith('/') && MemoryExtensions.Equals(uriPathOnly, _baseUri.OriginalString.AsSpan(0, _baseUri.OriginalString.Length - 1), StringComparison.Ordinal))
255+
{
256+
// Special case: for the base URI "/something/", if you're at
257+
// "/something" then treat it as if you were at "/something/" (i.e.,
258+
// with the trailing slash). It's a bit ambiguous because we don't know
259+
// whether the server would return the same page whether or not the
260+
// slash is present, but ASP.NET Core at least does by default when
261+
// using PathBase.
262+
return uri[..(_baseUri.OriginalString.Length - 1)];
263+
}
264+
265+
var message = $"The URI '{uri}' is not contained by the base URI '{_baseUri}'.";
266+
throw new ArgumentException(message);
267+
}
268+
243269
internal static string NormalizeBaseUri(string baseUri)
244270
{
245271
var lastSlashIndex = baseUri.LastIndexOf('/');

0 commit comments

Comments
 (0)