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 MemoryExtensions.Split in MimeBasePart.DetectEncoding #80211

Merged
merged 1 commit into from Jan 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,7 +10,6 @@ namespace System.Net.Mime
internal class MimeBasePart
{
internal const string DefaultCharSet = "utf-8";
private static readonly char[] s_decodeEncodingSplitChars = new char[] { '?', '\r', '\n' };

protected ContentType? _contentType;
protected ContentDisposition? _contentDisposition;
Expand Down Expand Up @@ -96,14 +95,16 @@ internal static string DecodeHeaderValue(string? value)
return null;
}

string[] subStrings = value.Split(s_decodeEncodingSplitChars);
if ((subStrings.Length < 5 || subStrings[0] != "=" || subStrings[4] != "="))
ReadOnlySpan<char> valueSpan = value;
Span<Range> subStrings = stackalloc Range[6];
if (valueSpan.SplitAny(subStrings, "?\r\n") < 5 ||
valueSpan[subStrings[0]] is not "=" ||
valueSpan[subStrings[4]] is not "=")
{
return null;
}

string charSet = subStrings[1];
return Encoding.GetEncoding(charSet);
return Encoding.GetEncoding(value[subStrings[1]]);
}

internal static bool IsAscii(string value, bool permitCROrLF)
Expand Down