Skip to content

Commit 8934139

Browse files
committed
Merge branch 'release/4.2.0'
2 parents 08b3fc5 + 32b65dc commit 8934139

15 files changed

Lines changed: 212 additions & 130 deletions
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.IO;
2+
using System.Linq;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace HttpMultipartParser.UnitTests.ParserScenarios
8+
{
9+
public class EmptyForm
10+
{
11+
private static readonly string _testData = TestUtil.TrimAllLines(
12+
@"------WebKitFormBoundaryb4SfPlH9Bv7c2PKS--"
13+
);
14+
15+
private static readonly TestData _testCase = new TestData(
16+
_testData,
17+
Enumerable.Empty<ParameterPart>().ToList(),
18+
Enumerable.Empty<FilePart>().ToList()
19+
);
20+
21+
public EmptyForm()
22+
{
23+
foreach (var filePart in _testCase.ExpectedFileData)
24+
{
25+
filePart.Data.Position = 0;
26+
}
27+
}
28+
29+
[Fact]
30+
public void Parse_empty_form_boundary_specified()
31+
{
32+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
33+
{
34+
var parser = MultipartFormDataParser.Parse(stream, "----WebKitFormBoundaryb4SfPlH9Bv7c2PKS");
35+
Assert.True(_testCase.Validate(parser));
36+
}
37+
}
38+
39+
[Fact]
40+
public void Parse_empty_form_boundary_omitted()
41+
{
42+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
43+
{
44+
var parser = MultipartFormDataParser.Parse(stream);
45+
Assert.True(_testCase.Validate(parser));
46+
}
47+
}
48+
49+
[Fact]
50+
public async Task Parse_empty_form_boundary_specified_async()
51+
{
52+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
53+
{
54+
var parser = await MultipartFormDataParser.ParseAsync(stream, "----WebKitFormBoundaryb4SfPlH9Bv7c2PKS").ConfigureAwait(false);
55+
Assert.True(_testCase.Validate(parser));
56+
}
57+
}
58+
59+
[Fact]
60+
public async Task Parse_empty_form_boundary_omitted_async()
61+
{
62+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
63+
{
64+
var parser = await MultipartFormDataParser.ParseAsync(stream).ConfigureAwait(false);
65+
Assert.True(_testCase.Validate(parser));
66+
}
67+
}
68+
}
69+
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/ExactBufferTruncate.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1111
/// </summary>
1212
public class ExactBufferTruncate
1313
{
14-
private static readonly string _testData = TestUtil.TrimAllLines(@"--boundry
14+
private static readonly string _testData = TestUtil.TrimAllLines(
15+
@"--boundry
1516
Content-Disposition: form-data; name=""text""
1617
1718
textdata
@@ -20,7 +21,8 @@ public class ExactBufferTruncate
2021
Content-Type: text/plain
2122
2223
1234567890123456789012
23-
--boundry--");
24+
--boundry--"
25+
);
2426

2527
/// <summary>
2628
/// This test has the buffer split such that the final '--' of the end boundary

Source/HttpMultipartParser.UnitTests/ParserScenarios/FileIsLast.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class FileIsLast
2121
Content-Type: image/jpeg
2222
2323
BinaryData
24-
-----------------------------41952539122868--");
24+
-----------------------------41952539122868--"
25+
);
2526

2627
private static readonly TestData _testCase = new TestData(
2728
_testData,

Source/HttpMultipartParser.UnitTests/ParserScenarios/FullPathAsFileName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FullPathAsFileName
1515
1616
test
1717
-----------------------------7de6cc440a46--"
18-
);
18+
);
1919

2020
private static readonly TestData _testCase = new TestData(
2121
_testData,

Source/HttpMultipartParser.UnitTests/ParserScenarios/MixedSingleByteAndMultiByteWidth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MixedSingleByteAndMultiByteWidth
1919
2020
BinaryData
2121
-----------------------------41952539122868--"
22-
);
22+
);
2323

2424
private static readonly TestData _testCase = new TestData(
2525
_testData,

Source/HttpMultipartParser.UnitTests/ParserScenarios/MixedUnicodeWidthAndAsciiWidthCharacters.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class MixedUnicodeWidthAndAsciiWidthCharacters
1010
{
1111
private static readonly string _testData = TestUtil.TrimAllLines(
1212
@"--boundary_.oOo._MjQ1NTU=OTk3Ng==MjcxODE=
13-
Content-Disposition: form-data; name=""psAdTitle""
13+
Content-Disposition: form-data; name=""psAdTitle""
1414
15-
Bonjour poignée
16-
--boundary_.oOo._MjQ1NTU=OTk3Ng==MjcxODE=--"
17-
);
15+
Bonjour poignée
16+
--boundary_.oOo._MjQ1NTU=OTk3Ng==MjcxODE=--"
17+
);
1818

1919
private static readonly TestData _testCase = new TestData(
2020
_testData,

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleFilesWithEmptyName.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1212
/// </summary>
1313
public class MultipleFilesWithEmptyName
1414
{
15-
private static readonly string MultipleFilesSameName_testData = TestUtil.TrimAllLines(@"--boundry
15+
private static readonly string _testData = TestUtil.TrimAllLines(
16+
@"--boundry
1617
Content-Disposition: form-data; name="""";filename=""file1.txt"";
1718
Content-Type: text/plain
1819
@@ -27,10 +28,11 @@ THIS IS TEXT FILE 2 !!!
2728
Content-Type: text/plain
2829
2930
This is text file 3 1234567890
30-
--boundry--");
31+
--boundry--"
32+
);
3133

3234
private static readonly TestData _testCase = new TestData(
33-
MultipleFilesSameName_testData,
35+
_testData,
3436
Enumerable.Empty<ParameterPart>().ToList(),
3537
new List<FilePart> {
3638
new FilePart( "", "file1.txt", TestUtil.StringToStreamNoBom("THIS IS TEXT FILE 1")),

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleFilesWithOmittedName.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1212
/// </summary>
1313
public class MultipleFilesWithOmittedName
1414
{
15-
private static readonly string MultipleFilesWithOmittedName_testData = TestUtil.TrimAllLines(@"--boundry
15+
private static readonly string _testData = TestUtil.TrimAllLines(@"--boundry
1616
Content-Disposition: form-data; filename=""file1.txt"";
1717
Content-Type: text/plain
1818
@@ -27,10 +27,11 @@ THIS IS TEXT FILE 2 !!!
2727
Content-Type: text/plain
2828
2929
This is text file 3 1234567890
30-
--boundry--");
30+
--boundry--"
31+
);
3132

3233
private static readonly TestData _testCase = new TestData(
33-
MultipleFilesWithOmittedName_testData,
34+
_testData,
3435
Enumerable.Empty<ParameterPart>().ToList(),
3536
new List<FilePart> {
3637
new FilePart( null, "file1.txt", TestUtil.StringToStreamNoBom("THIS IS TEXT FILE 1")),

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleFilesWithSameName.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1212
/// </summary>
1313
public class MultipleFilesWithSameName
1414
{
15-
private static readonly string MultipleFilesSameName_testData = TestUtil.TrimAllLines(@"--boundry
16-
Content-Disposition: form-data; name=""file1.txt"";filename=""file1.txt"";
17-
Content-Type: text/plain
15+
private static readonly string _testData = TestUtil.TrimAllLines(
16+
@"--boundry
17+
Content-Disposition: form-data; name=""file1.txt"";filename=""file1.txt"";
18+
Content-Type: text/plain
1819
19-
THIS IS TEXT FILE 1
20-
--boundry
21-
Content-Disposition: form-data; name=""file2.txt"";filename=""file2.txt"";
22-
Content-Type: text/plain
20+
THIS IS TEXT FILE 1
21+
--boundry
22+
Content-Disposition: form-data; name=""file2.txt"";filename=""file2.txt"";
23+
Content-Type: text/plain
2324
24-
THIS IS TEXT FILE 2 !!!
25-
--boundry
26-
Content-Disposition: form-data; name=""file2.txt"";filename=""file2.txt"";
27-
Content-Type: text/plain
25+
THIS IS TEXT FILE 2 !!!
26+
--boundry
27+
Content-Disposition: form-data; name=""file2.txt"";filename=""file2.txt"";
28+
Content-Type: text/plain
2829
29-
This is text file 3 1234567890
30-
--boundry--");
30+
This is text file 3 1234567890
31+
--boundry--"
32+
);
3133

3234
private static readonly TestData _testCase = new TestData(
33-
MultipleFilesSameName_testData,
35+
_testData,
3436
Enumerable.Empty<ParameterPart>().ToList(),
3537
new List<FilePart> {
3638
new FilePart( "file1.txt", "file1.txt", TestUtil.StringToStreamNoBom("THIS IS TEXT FILE 1")),

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleParamsAndFiles.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,38 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1111
/// </summary>
1212
public class MultipleParamsAndFiles
1313
{
14-
private static readonly string MultipleParamsAndFiles_testData = TestUtil.TrimAllLines(@"--boundry
15-
Content-Disposition: form-data; name=""text""
14+
private static readonly string _testData = TestUtil.TrimAllLines(
15+
@"--boundry
16+
Content-Disposition: form-data; name=""text""
1617
17-
textdata
18-
--boundry
19-
Content-Disposition: form-data; name=""after"";TestForTextWithoutSplit
18+
textdata
19+
--boundry
20+
Content-Disposition: form-data; name=""after"";TestForTextWithoutSplit
2021
21-
afterdata
22-
--boundry
23-
Content-Disposition: form-data; name=""file""; filename=""data.txt""
24-
Content-Type: text/plain
22+
afterdata
23+
--boundry
24+
Content-Disposition: form-data; name=""file""; filename=""data.txt""
25+
Content-Type: text/plain
2526
26-
I am the first data
27-
--boundry
28-
Content-Disposition: form-data;TestForTextWithoutSplit; name=""newfile""; filename=""superdata.txt""
29-
Content-Type: text/plain
27+
I am the first data
28+
--boundry
29+
Content-Disposition: form-data;TestForTextWithoutSplit; name=""newfile""; filename=""superdata.txt""
30+
Content-Type: text/plain
3031
31-
I am the second data
32-
--boundry
33-
Content-Disposition: form-data; name=""never""
32+
I am the second data
33+
--boundry
34+
Content-Disposition: form-data; name=""never""
3435
35-
neverdata
36-
--boundry
37-
Content-Disposition: form-data; name=""waylater""
36+
neverdata
37+
--boundry
38+
Content-Disposition: form-data; name=""waylater""
3839
39-
waylaterdata
40-
--boundry--");
40+
waylaterdata
41+
--boundry--"
42+
);
4143

4244
private static readonly TestData _testCase = new TestData(
43-
MultipleParamsAndFiles_testData,
45+
_testData,
4446
new List<ParameterPart> {
4547
new ParameterPart("text", "textdata"),
4648
new ParameterPart("after", "afterdata"),

0 commit comments

Comments
 (0)