Skip to content

Commit 2ca91d0

Browse files
committed
Merge branch 'release/9.2.0'
2 parents 1368229 + a3f7ede commit 2ca91d0

18 files changed

+212
-180
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"cake.tool": {
6-
"version": "5.0.0",
6+
"version": "6.0.0",
77
"commands": [
88
"dotnet-cake"
99
]

CodeCoverage.runsettings

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<!-- Match fully qualified names of functions: -->
1111
<Functions>
1212
<Exclude>
13-
<Function>Http-Multipart-Data-Parser\.Properties\..*</Function>
14-
<Function>Http-Multipart-Data-Parser\.Models\..*</Function>
15-
<Function>Http-Multipart-Data-Parser\.Utilities\.Log\..*</Function>
13+
<Function>HttpMultipartParser\.Properties\..*</Function>
14+
<Function>HttpMultipartParser\.Models\..*</Function>
15+
<Function>HttpMultipartParser\.Utilities\.Log\..*</Function>
1616
<Function>System\.Text\.Json\.SourceGeneration\..*</Function>
1717
<Function>System\.Runtime\.CompilerServices\..*</Function>
1818
</Exclude>
@@ -21,7 +21,7 @@
2121
<!-- Match attributes on any code element: -->
2222
<Attributes>
2323
<Exclude>
24-
<Attribute>Http-Multipart-Data-Parser\.Utilities\.ExcludeFromCodeCoverageAttribute</Attribute>
24+
<Attribute>HttpMultipartParser\.Utilities\.ExcludeFromCodeCoverageAttribute</Attribute>
2525
<Attribute>System\.Obsolete</Attribute>
2626
<Attribute>System\.CodeDom\.Compiler\.GeneratedCodeAttribute</Attribute>
2727
<Attribute>System\.Runtime\.CompilerServices\.CompilerGeneratedAttribute</Attribute>

GitReleaseManager.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create:
22
include-footer: false
33
footer-heading: Where to get it
4-
footer-content: You can download this release from [nuget.org](https://www.nuget.org/packages/Http-Multipart-Data-Parser/{milestone})
4+
footer-content: You can download this release from [nuget.org](https://www.nuget.org/packages/HttpMultipartParser/{milestone})
55
footer-includes-milestone: true
66
milestone-replace-text: '{milestone}'
77
include-contributors: true
@@ -14,7 +14,7 @@ close:
1414
The release is available on:
1515
1616
- [GitHub Release](https://github.com/{owner}/{repository}/releases/tag/{milestone})
17-
- [NuGet Package](https://www.nuget.org/packages/Http-Multipart-Data-Parser/{milestone})
17+
- [NuGet Package](https://www.nuget.org/packages/HttpMultipartParser/{milestone})
1818
1919
Your **[GitReleaseManager](https://github.com/GitTools/GitReleaseManager)** bot :package::rocket:
2020
export:

Source/HttpMultipartParser.Benchmark/HttpMultipartParser.Benchmark.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
9+
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

Source/HttpMultipartParser.UnitTests/HttpMultipartParser.UnitTests.csproj

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net48;net9.0</TargetFrameworks>
4+
<TargetFrameworks>net48;net10.0</TargetFrameworks>
55
<AssemblyName>HttpMultipartParser.UnitTests</AssemblyName>
66
<RootNamespace>HttpMultipartParser.UnitTests</RootNamespace>
77
<IsPackable>false</IsPackable>
88
<IsTestProject>true</IsTestProject>
99
<OutputType>Exe</OutputType>
1010
</PropertyGroup>
1111

12-
<!-- Enable the MSTest runner -->
1312
<PropertyGroup>
14-
<EnableMSTestRunner>true</EnableMSTestRunner>
15-
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
13+
<!--
14+
UseMicrosoftTestingPlatformRunner continues to be necessary for .NET 10, because this flag has nothing to do with dotnet test.
15+
It changes how dotnet run works, which is completely independent of dotnet test.
16+
https://github.com/xunit/xunit/issues/3421
17+
-->
1618
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
1719
</PropertyGroup>
1820

1921
<ItemGroup>
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
21-
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" />
22-
<PackageReference Include="xunit.v3" Version="3.0.1" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
23+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
24+
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.0" />
2325
</ItemGroup>
2426

2527
<ItemGroup>

Source/HttpMultipartParser.UnitTests/ParserScenarios/FileChunkStartsWithBOM.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ public class FileChunkStartsWithBOM
2323
private static readonly string _fileContent = $"{_padding}{_utf8BOMString}Hello world";
2424

2525
private static readonly string _testDataFormat =
26-
@"{0}{1}
26+
@"{0}{1}
2727
--boundary--";
2828
private static readonly string _testData = TestUtil.TrimAllLines(string.Format(_testDataFormat, _prefix, _fileContent));
2929

30-
/// <summary>
31-
/// Test case for files with additional parameter.
32-
/// </summary>
3330
private static readonly TestData _testCase = new TestData(
3431
_testData,
3532
new List<ParameterPart> { },
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text;
5+
using Xunit;
6+
7+
namespace HttpMultipartParser.UnitTests.ParserScenarios
8+
{
9+
// This test attempts to reproduce the bug discussed here:
10+
// https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/40
11+
public class FileLineSpansAccrossTwoChunks
12+
{
13+
private static readonly string part1 = "--boundary\r\nContent-Disposition: form-data; name=\"param1\"\r\n\r\nFirst value\r\n";
14+
private static readonly string part2 = "--boundary\r\nContent-Disposition: form-data; name=\"param2\"\r\n\r\nSecond value\r\n--boundary--";
15+
16+
// Buffer size is calculated to split the '\r' and '\n' after "First value"
17+
private static readonly int _binaryBufferSize = part1.Length - 1;
18+
private static readonly string _testData = TestUtil.TrimAllLines($"{part1}{part2}");
19+
20+
private static readonly TestData _testCase = new TestData(
21+
_testData,
22+
new List<ParameterPart>
23+
{
24+
new ParameterPart("param1", "First value"),
25+
new ParameterPart("param2", "Second value"),
26+
},
27+
Enumerable.Empty<FilePart>().ToList()
28+
);
29+
30+
/// <summary>
31+
/// Initializes the test data before each run, this primarily
32+
/// consists of resetting data stream positions.
33+
/// </summary>
34+
public FileLineSpansAccrossTwoChunks()
35+
{
36+
foreach (var filePart in _testCase.ExpectedFileData)
37+
{
38+
filePart.Data.Position = 0;
39+
}
40+
}
41+
42+
[Fact]
43+
public void CanHandleNewLineAccrossTwoChunks()
44+
{
45+
var options = new ParserOptions
46+
{
47+
Boundary = "boundary",
48+
BinaryBufferSize = _binaryBufferSize,
49+
Encoding = Encoding.UTF8
50+
};
51+
52+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, options.Encoding))
53+
{
54+
var parser = MultipartFormDataParser.Parse(stream, options);
55+
Assert.True(_testCase.Validate(parser));
56+
}
57+
}
58+
}
59+
}

Source/HttpMultipartParser.UnitTests/RebufferableBinaryReaderUnitTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,26 @@ public async Task ReadCanResumeInterruptedStreamAsync()
404404

405405
#region ReadByteLine() Tests
406406

407+
[Fact]
408+
// This unit test verifies that ReadByteLine can read a line which spans multiple chunks.
409+
// https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/40
410+
public void CanReadByteLineAccrossChunks()
411+
{
412+
// For this test to truly demonstrate that we can read a line which spans multiple chunks,
413+
// the newline needs to be at a position greater than the buffer size.
414+
var bufferSize = 5;
415+
var inputString = "0123456789ab\r\ncde";
416+
417+
var reader = new RebufferableBinaryReader(TestUtil.StringToStreamNoBom(inputString), Encoding.UTF8, bufferSize);
418+
var bytes = reader.ReadByteLine();
419+
var expected = Encoding.UTF8.GetBytes("0123456789ab");
420+
421+
foreach (var pair in expected.Zip(bytes, Tuple.Create))
422+
{
423+
Assert.Equal(pair.Item1, pair.Item2);
424+
}
425+
}
426+
407427
[Fact]
408428
public void CanReadByteLineOnMixedAsciiAndUTF8Text()
409429
{
@@ -421,6 +441,26 @@ public void CanReadByteLineOnMixedAsciiAndUTF8Text()
421441

422442
#region ReadByteLineAsync() Tests
423443

444+
[Fact]
445+
// This unit test verifies that ReadByteLine can read a line which spans multiple chunks.
446+
// https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/40
447+
public async Task CanReadByteLineAsyncAccrossChunks()
448+
{
449+
// For this test to truly demonstrate that we can read a line which spans multiple chunks,
450+
// the newline needs to be at a position greater than the buffer size.
451+
var bufferSize = 5;
452+
var inputString = "0123456789ab\r\ncde";
453+
454+
var reader = new RebufferableBinaryReader(TestUtil.StringToStreamNoBom(inputString), Encoding.UTF8, bufferSize);
455+
var bytes = await reader.ReadByteLineAsync(TestContext.Current.CancellationToken);
456+
var expected = Encoding.UTF8.GetBytes("0123456789ab");
457+
458+
foreach (var pair in expected.Zip(bytes, Tuple.Create))
459+
{
460+
Assert.Equal(pair.Item1, pair.Item2);
461+
}
462+
}
463+
424464
[Fact]
425465
public async Task CanReadByteLineOnMixedAsciiAndUTF8TextAsync()
426466
{

Source/HttpMultipartParser.UnitTests/StreamingMultipartFormDataParserUnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,21 @@ public async Task CanHandleNullDelegatesAsync()
6363
await parser.RunAsync(TestContext.Current.CancellationToken);
6464
}
6565
}
66+
67+
[Fact]
68+
public void CanHandleDefaultOptions()
69+
{
70+
using (Stream stream = TestUtil.StringToStream(_testData))
71+
{
72+
var parser = new StreamingMultipartFormDataParser(stream);
73+
74+
// Intentionally setting these handlers to null to verify that we can parse the stream despite missing handlers
75+
// See: https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/121
76+
parser.ParameterHandler = null;
77+
parser.FileHandler = null;
78+
79+
parser.Run();
80+
}
81+
}
6682
}
6783
}

Source/HttpMultipartParser.sln

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)