Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add /// comments
  • Loading branch information
MihaZupan authored and github-actions committed Sep 17, 2021
commit 56c34da1e8a82f8f5d80073ee5690aaeda7f2368
8 changes: 8 additions & 0 deletions src/libraries/System.Private.Uri/src/System/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ internal enum Flags : ulong
IriCanonical = 0x78000000000,
UnixPath = 0x100000000000,

/// <summary>
/// Disables any validation/normalization past the authority. Fragments will always be empty. GetComponents will throw for Path/Query.
/// </summary>
DisablePathAndQueryCanonicalization = 0x200000000000,

/// <summary>
Expand Down Expand Up @@ -414,6 +417,11 @@ public Uri(string uriString, UriKind uriKind)
DebugSetLeftCtor();
}

/// <summary>
/// Initializes a new instance of the <see cref="Uri"/> class with the specified URI and additional <see cref="UriCreationOptions"/>.
/// </summary>
/// <param name="uriString">A string that identifies the resource to be represented by the <see cref="Uri"/> instance.</param>
/// <param name="creationOptions">Options that control how the <seealso cref="Uri"/> is created and behaves.</param>
public Uri(string uriString, in UriCreationOptions creationOptions)
{
if (uriString is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@

namespace System
{
/// <summary>
/// Options that control how a <seealso cref="Uri"/> is created and behaves.
/// </summary>
public struct UriCreationOptions
{
public bool DangerousDisablePathAndQueryCanonicalization { readonly get; set; }
private bool _disablePathAndQueryCanonicalization;

/// <summary>
/// Disables validation and normalization of the Path and Query.
/// No transformations of the URI past the Authority will take place.
/// <see cref="Uri"/> instances created with this option do not support <see cref="Uri.Fragment"/>s.
/// <see cref="Uri.GetComponents(UriComponents, UriFormat)"/> may not be used for <see cref="UriComponents.Path"/> or <see cref="UriComponents.Query"/>.
/// Be aware that disabling canonicalization also means that reserved characters will not be escaped,
/// which may corrupt the HTTP request and makes the application subject to request smuggling.
/// Only set this option if you have ensured that the URI string is already sanitized.
/// </summary>
public bool DangerousDisablePathAndQueryCanonicalization
{
readonly get => _disablePathAndQueryCanonicalization;
set => _disablePathAndQueryCanonicalization = value;
}
}
}
7 changes: 7 additions & 0 deletions src/libraries/System.Private.Uri/src/System/UriExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ public static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriK
return e is null && result != null;
}

/// <summary>
/// Creates a new <see cref="Uri"/> using the specified <see cref="string"/> instance and <see cref="UriCreationOptions"/>.
/// </summary>
/// <param name="uriString">The string representation of the <see cref="Uri"/>.</param>
/// <param name="creationOptions">Options that control how the <seealso cref="Uri"/> is created and behaves.</param>
/// <param name="result">The constructed <see cref="Uri"/>.</param>
/// <returns><see langword="true"/> if the <see cref="Uri"/> was successfully created; otherwise, <see langword="false"/>.</returns>
public static bool TryCreate([NotNullWhen(true)] string? uriString, in UriCreationOptions creationOptions, [NotNullWhen(true)] out Uri? result)
{
if (uriString is null)
Expand Down