Skip to content
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
Use MemoryExtensions.Split in MimeBasePart.DetectEncoding
  • Loading branch information
stephentoub committed Jan 4, 2023
commit 419d13b5ed74db42cc984cc607a02e00d0fe22e6
Original file line number Diff line number Diff line change
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