Skip to content

Commit c1a2f05

Browse files
committed
Merge branch 'release/8.2.0'
2 parents 397ebad + 4e83b57 commit c1a2f05

14 files changed

+222
-85
lines changed

.editorconfig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ insert_final_newline = false
1111
trim_trailing_whitespace = true
1212

1313
# .NET Code files
14-
[*.{cs,csx,cake,vb}]
14+
[*.{cs,csx,cake,vb,vbx,h,cpp,idl}]
1515
indent_style = tab
1616
tab_width = 4
1717
insert_final_newline = true
@@ -21,12 +21,12 @@ insert_final_newline = true
2121
indent_style = tab
2222
tab_width = 4
2323

24-
# Visual Studio XML Project Files
25-
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
24+
# MSBuild project files
25+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,msbuildproj}]
2626
indent_size = 2
2727

28-
# Various XML Configuration Files
29-
[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}]
28+
# Xml config files
29+
[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct,runsettings}]
3030
indent_size = 2
3131

3232
# JSON Files

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,6 @@
9494
*.DOT diff=astextplain
9595
*.rtf diff=astextplain
9696
*.RTF diff=astextplain
97+
98+
# The macOS codesign tool is extremely picky, and requires LF line endings.
99+
*.plist eol=lf
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace HttpMultipartParser.UnitTests.ParserScenarios
8+
{
9+
public class BlankLinesBeforeFirstBoundary
10+
{
11+
private static readonly string _testData = TestUtil.TrimAllLines(
12+
@"--boundary
13+
Content-Disposition: form-data; name=""text""
14+
15+
textdata
16+
--boundary--"
17+
);
18+
19+
// This test case has a few blank lines before the first boundary marker
20+
// This unusual scenario is described in GH-116
21+
// https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/116
22+
private static readonly TestData _testCase = new TestData(
23+
$"\n\n\n{_testData}", // Intentionally add a few blank lines before the data. These blank lines should be ignored by the parser when attempting to detect the boundary marker
24+
new List<ParameterPart> {
25+
new ParameterPart("text", "textdata"),
26+
},
27+
new List<FilePart>()
28+
);
29+
30+
public BlankLinesBeforeFirstBoundary()
31+
{
32+
foreach (var filePart in _testCase.ExpectedFileData)
33+
{
34+
filePart.Data.Position = 0;
35+
}
36+
}
37+
38+
/// <summary>
39+
/// Tests for correct detection of the boundary in the input stream.
40+
/// </summary>
41+
[Fact]
42+
public void CanAutoDetectBoundary()
43+
{
44+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
45+
{
46+
var parser = MultipartFormDataParser.Parse(stream);
47+
Assert.True(_testCase.Validate(parser));
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Tests for correct detection of the boundary in the input stream.
53+
/// </summary>
54+
[Fact]
55+
public async Task CanAutoDetectBoundaryAsync()
56+
{
57+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
58+
{
59+
var parser = await MultipartFormDataParser.ParseAsync(stream, Encoding.UTF8).ConfigureAwait(false);
60+
Assert.True(_testCase.Validate(parser));
61+
}
62+
}
63+
}
64+
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/ExactBufferTruncate.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1212
public class ExactBufferTruncate
1313
{
1414
private static readonly string _testData = TestUtil.TrimAllLines(
15-
@"--boundry
15+
@"--boundary
1616
Content-Disposition: form-data; name=""text""
1717
1818
textdata
19-
--boundry
19+
--boundary
2020
Content-Disposition: form-data; name=""file""; filename=""data.txt""
2121
Content-Type: text/plain
2222
2323
1234567890123456789012
24-
--boundry--"
24+
--boundary--"
2525
);
2626

2727
/// <summary>
@@ -54,7 +54,7 @@ public void CanHandleFinalDashesInSeperateBufferFromEndBinary()
5454
{
5555
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
5656
{
57-
var parser = MultipartFormDataParser.Parse(stream, "boundry", Encoding.UTF8, 16);
57+
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
5858
Assert.True(_testCase.Validate(parser));
5959
}
6060
}
@@ -67,7 +67,7 @@ public async Task CanHandleFinalDashesInSeperateBufferFromEndBinaryAsync()
6767
{
6868
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
6969
{
70-
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundry", Encoding.UTF8, 16).ConfigureAwait(false);
70+
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
7171
Assert.True(_testCase.Validate(parser));
7272
}
7373
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleFilesWithEmptyName.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1313
public class MultipleFilesWithEmptyName
1414
{
1515
private static readonly string _testData = TestUtil.TrimAllLines(
16-
@"--boundry
16+
@"--boundary
1717
Content-Disposition: form-data; name="""";filename=""file1.txt"";
1818
Content-Type: text/plain
1919
2020
THIS IS TEXT FILE 1
21-
--boundry
21+
--boundary
2222
Content-Disposition: form-data; name="""";filename=""file2.txt"";
2323
Content-Type: text/plain
2424
2525
THIS IS TEXT FILE 2 !!!
26-
--boundry
26+
--boundary
2727
Content-Disposition: form-data; name="""";filename=""file3.txt"";
2828
Content-Type: text/plain
2929
3030
This is text file 3 1234567890
31-
--boundry--"
31+
--boundary--"
3232
);
3333

3434
private static readonly TestData _testCase = new TestData(
@@ -54,7 +54,7 @@ public void MultipleFilesWithNoNameTest()
5454
{
5555
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
5656
{
57-
var parser = MultipartFormDataParser.Parse(stream, "boundry", Encoding.UTF8, 16);
57+
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
5858
Assert.True(_testCase.Validate(parser));
5959
}
6060
}
@@ -64,7 +64,7 @@ public async Task MultipleFilesWithNoNameAsync()
6464
{
6565
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
6666
{
67-
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundry", Encoding.UTF8, 16).ConfigureAwait(false);
67+
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
6868
Assert.True(_testCase.Validate(parser));
6969
}
7070
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleFilesWithOmittedName.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1313
public class MultipleFilesWithOmittedName
1414
{
1515
private static readonly string _testData = TestUtil.TrimAllLines(
16-
@"--boundry
16+
@"--boundary
1717
Content-Disposition: form-data; filename=""file1.txt"";
1818
Content-Type: text/plain
1919
2020
THIS IS TEXT FILE 1
21-
--boundry
21+
--boundary
2222
Content-Disposition: form-data; filename=""file2.txt"";
2323
Content-Type: text/plain
2424
2525
THIS IS TEXT FILE 2 !!!
26-
--boundry
26+
--boundary
2727
Content-Disposition: form-data; filename=""file3.txt"";
2828
Content-Type: text/plain
2929
3030
This is text file 3 1234567890
31-
--boundry--"
31+
--boundary--"
3232
);
3333

3434
private static readonly TestData _testCase = new TestData(
@@ -54,7 +54,7 @@ public void MultipleFilesWithOmittedNameTest()
5454
{
5555
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
5656
{
57-
var parser = MultipartFormDataParser.Parse(stream, "boundry", Encoding.UTF8, 16);
57+
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
5858
Assert.True(_testCase.Validate(parser));
5959
}
6060
}
@@ -64,7 +64,7 @@ public async Task MultipleFilesWithOmittedNameAsync()
6464
{
6565
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
6666
{
67-
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundry", Encoding.UTF8, 16).ConfigureAwait(false);
67+
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
6868
Assert.True(_testCase.Validate(parser));
6969
}
7070
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleFilesWithSameName.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1313
public class MultipleFilesWithSameName
1414
{
1515
private static readonly string _testData = TestUtil.TrimAllLines(
16-
@"--boundry
16+
@"--boundary
1717
Content-Disposition: form-data; name=""file1.txt"";filename=""file1.txt"";
1818
Content-Type: text/plain
1919
2020
THIS IS TEXT FILE 1
21-
--boundry
21+
--boundary
2222
Content-Disposition: form-data; name=""file2.txt"";filename=""file2.txt"";
2323
Content-Type: text/plain
2424
2525
THIS IS TEXT FILE 2 !!!
26-
--boundry
26+
--boundary
2727
Content-Disposition: form-data; name=""file2.txt"";filename=""file2.txt"";
2828
Content-Type: text/plain
2929
3030
This is text file 3 1234567890
31-
--boundry--"
31+
--boundary--"
3232
);
3333

3434
private static readonly TestData _testCase = new TestData(
@@ -54,7 +54,7 @@ public void MultipleFilesWithSameNameTest()
5454
{
5555
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
5656
{
57-
var parser = MultipartFormDataParser.Parse(stream, "boundry", Encoding.UTF8, 16);
57+
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
5858
Assert.True(_testCase.Validate(parser));
5959
}
6060
}
@@ -64,7 +64,7 @@ public async Task MultipleFilesWithSameNameTestAsync()
6464
{
6565
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
6666
{
67-
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundry", Encoding.UTF8, 16).ConfigureAwait(false);
67+
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
6868
Assert.True(_testCase.Validate(parser));
6969
}
7070
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/MultipleParamsAndFiles.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
1212
public class MultipleParamsAndFiles
1313
{
1414
private static readonly string _testData = TestUtil.TrimAllLines(
15-
@"--boundry
15+
@"--boundary
1616
Content-Disposition: form-data; name=""text""
1717
1818
textdata
19-
--boundry
19+
--boundary
2020
Content-Disposition: form-data; name=""after"";TestForTextWithoutSplit
2121
2222
afterdata
23-
--boundry
23+
--boundary
2424
Content-Disposition: form-data; name=""file""; filename=""data.txt""
2525
Content-Type: text/plain
2626
2727
I am the first data
28-
--boundry
28+
--boundary
2929
Content-Disposition: form-data;TestForTextWithoutSplit; name=""newfile""; filename=""superdata.txt""
3030
Content-Type: text/plain
3131
3232
I am the second data
33-
--boundry
33+
--boundary
3434
Content-Disposition: form-data; name=""never""
3535
3636
neverdata
37-
--boundry
37+
--boundary
3838
Content-Disposition: form-data; name=""waylater""
3939
4040
waylaterdata
41-
--boundry--"
41+
--boundary--"
4242
);
4343

4444
private static readonly TestData _testCase = new TestData(
@@ -68,7 +68,7 @@ public void MultipleFilesAndParamsTest()
6868
{
6969
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
7070
{
71-
var parser = MultipartFormDataParser.Parse(stream, "boundry", Encoding.UTF8, 16);
71+
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
7272
Assert.True(_testCase.Validate(parser));
7373
}
7474
}
@@ -78,7 +78,7 @@ public async Task MultipleFilesAndParamsTestAsync()
7878
{
7979
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
8080
{
81-
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundry", Encoding.UTF8, 16).ConfigureAwait(false);
81+
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
8282
Assert.True(_testCase.Validate(parser));
8383
}
8484
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/SingleFile.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace HttpMultipartParser.UnitTests.ParserScenarios
99
public class SingleFile
1010
{
1111
private static readonly string _testData = TestUtil.TrimAllLines(
12-
@"--boundry
12+
@"--boundary
1313
Content-Disposition: form-data; name=""file""; filename=""data.txt"";
1414
Content-Type: text/plain
1515
1616
I am the first data1
17-
--boundry--"
17+
--boundary--"
1818
);
1919

2020
/// <summary>
@@ -45,7 +45,7 @@ public void SingleFileTest()
4545
{
4646
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
4747
{
48-
var parser = MultipartFormDataParser.Parse(stream, "boundry", Encoding.UTF8, 16);
48+
var parser = MultipartFormDataParser.Parse(stream, "boundary", Encoding.UTF8, 16);
4949
Assert.True(_testCase.Validate(parser));
5050
}
5151
}
@@ -55,7 +55,7 @@ public async Task SingleFileTest_Async()
5555
{
5656
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
5757
{
58-
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundry", Encoding.UTF8, 16).ConfigureAwait(false);
58+
var parser = await MultipartFormDataParser.ParseAsync(stream, "boundary", Encoding.UTF8, 16).ConfigureAwait(false);
5959
Assert.True(_testCase.Validate(parser));
6060
}
6161
}

Source/HttpMultipartParser.UnitTests/ParserScenarios/SmallData.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public void SmallDataTest()
5858
{
5959
using (Stream stream = TestUtil.StringToStream(_testCase.Request))
6060
{
61-
// The boundry is missing the first two -- in accordance with the multipart
62-
// spec. (A -- is added by the parser, this boundry is what would be sent in the
61+
// The boundary is missing the first two -- in accordance with the multipart
62+
// spec. (A -- is added by the parser, this boundary is what would be sent in the
6363
// request header)
6464
var parser = MultipartFormDataParser.Parse(stream, "---------------------------265001916915724");
6565
Assert.True(_testCase.Validate(parser));
@@ -71,8 +71,8 @@ public async Task SmallDataTestAsync()
7171
{
7272
using (Stream stream = TestUtil.StringToStream(_testCase.Request))
7373
{
74-
// The boundry is missing the first two -- in accordance with the multipart
75-
// spec. (A -- is added by the parser, this boundry is what would be sent in the
74+
// The boundary is missing the first two -- in accordance with the multipart
75+
// spec. (A -- is added by the parser, this boundary is what would be sent in the
7676
// requset header)
7777
var parser = await MultipartFormDataParser.ParseAsync(stream, "---------------------------265001916915724").ConfigureAwait(false);
7878
Assert.True(_testCase.Validate(parser));

0 commit comments

Comments
 (0)