Skip to content

Commit

Permalink
Merge branch 'release/8.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Jan 10, 2024
2 parents c1a2f05 + 2ec22e4 commit 8685415
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "3.0.0",
"version": "4.0.0",
"commands": [
"dotnet-cake"
]
Expand Down
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -46,7 +46,7 @@ public void ConstructingWithNullStreamFails()
[Fact]
public async Task ConstructingWithNullStreamFailsAsync()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => MultipartFormDataParser.ParseAsync(Stream.Null)).ConfigureAwait(false);
await Assert.ThrowsAsync<ArgumentNullException>(() => MultipartFormDataParser.ParseAsync(Stream.Null));
}

/// <summary>
Expand Down Expand Up @@ -89,7 +89,7 @@ line 3

using (Stream stream = TestUtil.StringToStream(request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.Equal($"line 1{Environment.NewLine}line 2{Environment.NewLine}line 3", parser.GetParameterValue("multilined"));
Assert.Equal($"line 1{Environment.NewLine}line 2{Environment.NewLine}line 3", parser.GetParameterValues("multilined").First());
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task HandlesFileWithLastCrLfAtBufferLengthAsync()

using (Stream stream = TestUtil.StringToStream(request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ public async Task HandlesFileWithLastCrLfImmediatlyAfterBufferLengthAsync()

using (Stream stream = TestUtil.StringToStream(request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
}
}

Expand All @@ -211,7 +211,7 @@ public async Task HandlesFileWithoutFilename()

using (Stream stream = TestUtil.StringToStream(request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.Single(parser.Files);
}
}
Expand Down
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Expand Up @@ -56,7 +56,7 @@ public async Task CanAutoDetectBoundaryAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -51,7 +51,7 @@ public async Task Parse_empty_form_boundary_specified_async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "----WebKitFormBoundaryb4SfPlH9Bv7c2PKS").ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "----WebKitFormBoundaryb4SfPlH9Bv7c2PKS");
Assert.True(_testCase.Validate(parser));
}
}
Expand All @@ -61,7 +61,7 @@ public async Task Parse_empty_form_boundary_omitted_async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -67,7 +67,7 @@ public async Task CanHandleFinalDashesInSeperateBufferFromEndBinaryAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public async Task CanHandleFileAsLastSectionAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -56,7 +56,7 @@ public async Task FileWithAdditionalParameterTest_Async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ public async Task HandlesFullPathAsFileNameWithSemicolonCorrectlyAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -44,7 +44,7 @@ public async Task Exception_is_thrown_when_attempting_to_parse_async()
// The default behavior is to throw an exception when the form contains an invalid section.
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream)).ConfigureAwait(false);
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream));
}
}

Expand All @@ -54,8 +54,8 @@ public void Invalid_part_is_ignored()
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = MultipartFormDataParser.Parse(stream, ignoreInvalidParts: true);
Assert.Equal(0, parser.Files.Count);
Assert.Equal(0, parser.Parameters.Count);
Assert.Empty(parser.Files);
Assert.Empty(parser.Parameters);
}
}

Expand All @@ -64,9 +64,9 @@ public async Task Invalid_part_is_ignored_async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, ignoreInvalidParts: true).ConfigureAwait(false);
Assert.Equal(0, parser.Files.Count);
Assert.Equal(0, parser.Parameters.Count);
var parser = await MultipartFormDataParser.ParseAsync(stream, ignoreInvalidParts: true);
Assert.Empty(parser.Files);
Assert.Empty(parser.Parameters);
}
}
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ public async Task CanHandleMixedSingleByteAndMultiByteWidthCharactersAsync()
Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8)
)
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public async Task CanHandleUnicodeWidthAndAsciiWidthCharactersAsync()
using (
Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public async Task MjpegStreamTest_Async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "MOBOTIX_Fast_Serverpush", Encoding.UTF8, 32).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "MOBOTIX_Fast_Serverpush", Encoding.UTF8, 32);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public async Task MultipleFilesWithNoNameAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public async Task MultipleFilesWithOmittedNameAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public async Task MultipleFilesWithSameNameTestAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ public async Task MultipleFilesAndParamsTestAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public async Task AcceptSeveralValuesWithSamePropertyAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -55,7 +55,7 @@ public async Task SingleFileTest_Async()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -73,8 +73,8 @@ public async Task SmallDataTestAsync()
{
// The boundary is missing the first two -- in accordance with the multipart
// spec. (A -- is added by the parser, this boundary is what would be sent in the
// requset header)
var parser = await MultipartFormDataParser.ParseAsync(stream, "---------------------------265001916915724").ConfigureAwait(false);
// request header)
var parser = await MultipartFormDataParser.ParseAsync(stream, "---------------------------265001916915724");
Assert.True(_testCase.Validate(parser));
}
}
Expand Down
Expand Up @@ -96,12 +96,12 @@ public async Task End_of_stream_and_boundary_is_known_async()
{
// Move the Position to the end of the stream
var sr = new StreamReader(stream);
var content = await sr.ReadToEndAsync().ConfigureAwait(false);
var content = await sr.ReadToEndAsync();

// When the developer provides the boundary, the parser does not have to determine the boundary
// and therefore the DetectBoundary method is not invoked which avoids the problem altogether.
// However, the parser is unable to find the provided boundary and throws a meaningful exception.
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream, "MyBoundary")).ConfigureAwait(false);
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream, "MyBoundary"));
}
}

Expand All @@ -112,10 +112,10 @@ public async Task End_of_stream_and_boundary_is_unknown_async()
{
// Move the Position to the end of the stream
var sr = new StreamReader(stream);
var content = await sr.ReadToEndAsync().ConfigureAwait(false);
var content = await sr.ReadToEndAsync();

// As of March 2022, the problem was resolved by throwing a more descriptive exception
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream)).ConfigureAwait(false);
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream));
}
}

Expand All @@ -130,7 +130,7 @@ public async Task Middle_of_stream_and_boundary_is_known_async()
// When the developer provides the boundary, the parser does not have to determine the boundary
// and therefore the DetectBoundary method is not invoked which avoids the problem altogether.
// However, the parser is unable to find the provided boundary and throws a meaningful exception.
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream, "MyBoundary")).ConfigureAwait(false);
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream, "MyBoundary"));
}
}

Expand All @@ -143,7 +143,7 @@ public async Task Middle_of_stream_and_boundary_is_unknown_async()
stream.Position = 3;

// As of March 2022, the problem was resolved by throwing a more descriptive exception
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream)).ConfigureAwait(false);
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream));
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Source/HttpMultipartParser.UnitTests/ParserScenarios/TinyData.cs
Expand Up @@ -67,7 +67,7 @@ public async Task CanAutoDetectBoundaryAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task CanDetectBoundariesCrossBufferAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public async Task CorrectlyHandleMixedNewlineFormatsAsync()
string request = regex.Replace(_testCase.Request, "\r\n", 1);
using (Stream stream = TestUtil.StringToStream(request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public async Task CorrectlyHandlesCRLFAsync()
string request = _testCase.Request.Replace("\n", "\r\n");
using (Stream stream = TestUtil.StringToStream(request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand All @@ -181,7 +181,7 @@ public async Task TinyDataTestAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8);
Assert.True(_testCase.Validate(parser));
}
}
Expand All @@ -204,7 +204,7 @@ public async Task DoesNotCloseTheStreamAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8);
Assert.True(_testCase.Validate(parser));

stream.Position = 0;
Expand All @@ -227,7 +227,7 @@ public async Task GetParameterValueReturnsNullIfNoParameterFoundAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8);
Assert.Null(parser.GetParameterValue("does not exist"));
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ public async Task CanDetectBoundriesWithNewLineInNextBufferAsync()
{
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, i).ConfigureAwait(false);
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, i);
Assert.True(_testCase.Validate(parser), $"Failure in buffer length {i}");
}
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ public async Task DoesntInfiniteLoopOnUnclosedInputAsync()
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
{
// We expect this to throw!
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8)).ConfigureAwait(false);
await Assert.ThrowsAsync<MultipartParseException>(() => MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8));
}
}
}
Expand Down

0 comments on commit 8685415

Please sign in to comment.