Skip to content

Commit 05adc64

Browse files
authored
Use IndexOfAnyValues in MultipartContent (#79788)
1 parent d354d3c commit 05adc64

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class MultipartContent : HttpContent, IEnumerable<HttpContent>
2323
private const int ColonSpaceLength = 2;
2424
private const int CommaSpaceLength = 2;
2525

26+
private static readonly IndexOfAnyValues<char> s_allowedBoundaryChars =
27+
IndexOfAnyValues.Create(" '()+,-./0123456789:=?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
28+
2629
private readonly List<HttpContent> _nestedContent;
2730
private readonly string _boundary;
2831

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

88-
const string AllowedMarks = @"'()+_,-./:=? ";
89-
90-
foreach (char ch in boundary)
91+
if (boundary.AsSpan().IndexOfAnyExcept(s_allowedBoundaryChars) >= 0)
9192
{
92-
if (!char.IsAsciiLetterOrDigit(ch) &&
93-
!AllowedMarks.Contains(ch)) // Marks.
94-
{
95-
throw new ArgumentException(SR.Format(System.Globalization.CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, boundary), nameof(boundary));
96-
}
93+
throw new ArgumentException(SR.Format(System.Globalization.CultureInfo.InvariantCulture, SR.net_http_headers_invalid_value, boundary), nameof(boundary));
9794
}
9895
}
9996

0 commit comments

Comments
 (0)