Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IndexOf in WebUtility.HtmlDecode #70700

Merged
merged 1 commit into from
Jun 14, 2022
Merged
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
19 changes: 2 additions & 17 deletions src/libraries/System.Private.CoreLib/src/System/Net/WebUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static void HtmlEncode(ReadOnlySpan<char> input, ref ValueStringBuilder

ReadOnlySpan<char> valueSpan = value.AsSpan();

int index = IndexOfHtmlDecodingChars(valueSpan);
int index = valueSpan.IndexOf('&');
if (index < 0)
{
return value;
Expand Down Expand Up @@ -215,7 +215,7 @@ public static void HtmlDecode(string? value, TextWriter output)

ReadOnlySpan<char> valueSpan = value.AsSpan();

int index = IndexOfHtmlDecodingChars(valueSpan);
int index = valueSpan.IndexOf('&');
if (index == -1)
{
output.Write(value);
Expand Down Expand Up @@ -701,21 +701,6 @@ private static bool ValidateUrlEncodingParameters(byte[]? bytes, int offset, int
return true;
}

private static int IndexOfHtmlDecodingChars(ReadOnlySpan<char> input)
{
// this string requires html decoding if it contains '&' or a surrogate character
for (int i = 0; i < input.Length; i++)
{
char c = input[i];
if (c == '&' || char.IsSurrogate(c))
{
return i;
}
}

return -1;
}

#endregion

// Internal struct to facilitate URL decoding -- keeps char buffer and byte buffer, allows appending of either chars or bytes
Expand Down