Skip to content

Commit

Permalink
Use IndexOfAnyValues in MultipartContent (dotnet#79788)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Jan 2, 2023
1 parent d354d3c commit 05adc64
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class MultipartContent : HttpContent, IEnumerable<HttpContent>
private const int ColonSpaceLength = 2;
private const int CommaSpaceLength = 2;

private static readonly IndexOfAnyValues<char> s_allowedBoundaryChars =
IndexOfAnyValues.Create(" '()+,-./0123456789:=?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");

private readonly List<HttpContent> _nestedContent;
private readonly string _boundary;

Expand Down Expand Up @@ -85,15 +88,9 @@ private static void ValidateBoundary(string boundary)
throw new ArgumentException(SR.Format(System.Globalization.CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, boundary), nameof(boundary));
}

const string AllowedMarks = @"'()+_,-./:=? ";

foreach (char ch in boundary)
if (boundary.AsSpan().IndexOfAnyExcept(s_allowedBoundaryChars) >= 0)
{
if (!char.IsAsciiLetterOrDigit(ch) &&
!AllowedMarks.Contains(ch)) // Marks.
{
throw new ArgumentException(SR.Format(System.Globalization.CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, boundary), nameof(boundary));
}
throw new ArgumentException(SR.Format(System.Globalization.CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, boundary), nameof(boundary));
}
}

Expand Down

0 comments on commit 05adc64

Please sign in to comment.