src/packages/EmbedIO/Utilities/UrlPath.cs
/// <summary>
/// Normalizes the specified URL path, assuming that it is valid.
/// </summary>
/// <param name="path">The URL path.</param>
/// <param name="isBasePath">if set to <see langword="true"/>, treat the URL path
/// as a base path, i.e. ensure it ends with a slash (<c>/</c>) character;
/// otherwise, ensure that it does NOT end with a slash character.</param>
/// <returns>The normalized path.</returns>
/// <remarks>
/// <para>A normalized URL path is one where each run of two or more slash
/// (<c>/</c>) characters has been replaced with a single slash character.</para>
/// <para>This method does NOT try to decode URL-encoded characters.</para>
/// <para>If <paramref name="path"/> is not valid, the behavior of
/// this method is unspecified. You should call this method only after
/// <see cref="IsValid"/> has returned <see langword="true"/>
/// for the same <paramref name="path"/>.</para>
/// <para>You should call <see cref="Normalize"/> instead of this method
/// if you are not sure that <paramref name="path"/> is valid.</para>
/// <para>There is no need to call this method for a method parameter
/// for which you have already called <see cref="Validate.UrlPath"/>.</para>
/// </remarks>
/// <seealso cref="Normalize"/>
/// <seealso cref="IsValid"/>
/// <seealso cref="Validate.UrlPath"/>
Normalizes the specified URL path, assuming that it is valid.
Normalizes the specified URL path assuming that it is valid .
public static string UnsafeNormalize(string path, bool isBasePath)
        {
            path = MultipleSlashRegex.Replace(path, "/");
            var length = path.Length;
            if (length == 1)
                return path;
            var finalPosition = length - 1;
            var endsWithSlash = path[finalPosition] == '/';
            return isBasePath
                ? (endsWithSlash ? path : path + "/")
                : (endsWithSlash ? path.Substring(0, finalPosition) : path);
        }
public static string UnsafeNormalize ( string path , bool isBasePath ) { path = MultipleSlashRegex . Replace ( path , " " ) ; var length = path . Length ; if ( length == 1 ) return path ; var finalPosition = length - 1 ; var endsWithSlash = path [ finalPosition ] == ' ' ; return isBasePath ? ( endsWithSlash ? path : path + " " ) : ( endsWithSlash ? path . Substring ( 0 , finalPosition ) : path ) ; }
Normalizes the specified URL path, assuming that it is valid.
Normalizes the specified URL path assuming that it is valid .
// Replace each run of multiple slashes with a single slash // The root path needs no further checking. // Base URL paths must end with a slash; // non-base URL paths must NOT end with a slash. // The final slash is irrelevant for the URL itself // (it has to map the same way with or without it) // but makes comparing and mapping URLs a lot simpler.
The normalized path.
The normalized path .
path
string
The URL path.
The URL path .
isBasePath
bool
if set to , treat the URL path
as a base path, i.e. ensure it ends with a slash (
if set to treat the URL path as a base path i . e . ensure it ends with a slash (
remarks
A normalized URL path is one where each run of two or more slash
(/This method does NOT try to decode URL-encoded characters.If  is not valid, the behavior of
this method is unspecified. You should call this method only after
has returned
for the same .You should call  instead of this method
if you are not sure that  is valid.There is no need to call this method for a method parameter
for which you have already called .
A normalized URL path is one where each run of two or more slash ( / This method does NOT try to decode URL - encoded characters . If is not valid the behavior of this method is unspecified . You should call this method only after has returned for the same . You should call instead of this method if you are not sure that is valid . There is no need to call this method for a method parameter for which you have already called .
seealso
None
seealso
None
seealso
None