Skip to content

Commit 2a37e57

Browse files
committed
Don't change properties name casing when parsing a section
Resolves #112
1 parent 1a12a3e commit 2a37e57

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Source/HttpMultipartParser.UnitTests/ParserScenarios/TestData.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ private bool ValidateFiles(MultipartFormDataParser parser)
113113
if (expectedFile.ContentDisposition != actualFile.ContentDisposition) return false;
114114

115115
if (expectedFile.AdditionalProperties.Count != actualFile.AdditionalProperties.Count) return false;
116-
if (expectedFile.AdditionalProperties.Except(actualFile.AdditionalProperties).Any()) return false;
116+
if (expectedFile.AdditionalProperties.Any(pair => !actualFile.AdditionalProperties.Keys.Contains(pair.Key, StringComparer.OrdinalIgnoreCase))) return false;
117+
if (actualFile.AdditionalProperties.Any(pair => !expectedFile.AdditionalProperties.Keys.Contains(pair.Key, StringComparer.OrdinalIgnoreCase))) return false;
118+
if (expectedFile.AdditionalProperties.Any(pair => actualFile.AdditionalProperties[pair.Key] != pair.Value)) return false; // Case-sensitive
117119

118120
// Read the data from the files and see if it's the same
119121
if (expectedFile.Data.CanSeek && expectedFile.Data.Position != 0) expectedFile.Data.Position = 0;

Source/HttpMultipartParser/FilePart.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// </summary>
2525
// --------------------------------------------------------------------------------------------------------------------
2626

27+
using System;
2728
using System.Collections.Generic;
2829
using System.Collections.ObjectModel;
2930
using System.IO;
@@ -97,7 +98,7 @@ public FilePart(string name, string fileName, Stream data, IDictionary<string, s
9798
Data = data;
9899
ContentType = contentType;
99100
ContentDisposition = contentDisposition;
100-
AdditionalProperties = new ReadOnlyDictionary<string, string>(additionalProperties ?? new Dictionary<string, string>());
101+
AdditionalProperties = new ReadOnlyDictionary<string, string>(additionalProperties ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase));
101102
}
102103

103104
#endregion

Source/HttpMultipartParser/StreamingMultipartFormDataParser.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ private void ParseSection(RebufferableBinaryReader reader)
10561056
// in the case of single file uploads. Multi-file uploads have Content-Disposition: file according
10571057
// to the spec however in practise it seems that multiple files will be represented by
10581058
// multiple Content-Disposition: form-data files.
1059-
var parameters = new Dictionary<string, string>();
1059+
var parameters = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
10601060

10611061
string line = reader.ReadLine();
10621062
while (line != string.Empty)
@@ -1091,8 +1091,9 @@ private void ParseSection(RebufferableBinaryReader reader)
10911091

10921092
// Limit split to 2 splits so we don't accidently split characters in file paths.
10931093
.ToDictionary(
1094-
x => x[0].Trim().Replace("\"", string.Empty).ToLower(),
1095-
x => x[1].Trim().Replace("\"", string.Empty));
1094+
x => x[0].Trim().Replace("\"", string.Empty),
1095+
x => x[1].Trim().Replace("\"", string.Empty),
1096+
StringComparer.OrdinalIgnoreCase);
10961097

10971098
// Here we just want to push all the values that we just retrieved into the
10981099
// parameters dictionary.
@@ -1155,7 +1156,7 @@ private async Task ParseSectionAsync(RebufferableBinaryReader reader, Cancellati
11551156
// in the case of single file uploads. Multi-file uploads have Content-Disposition: file according
11561157
// to the spec however in practise it seems that multiple files will be represented by
11571158
// multiple Content-Disposition: form-data files.
1158-
var parameters = new Dictionary<string, string>();
1159+
var parameters = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
11591160

11601161
string line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);
11611162
while (line != string.Empty)
@@ -1190,8 +1191,9 @@ private async Task ParseSectionAsync(RebufferableBinaryReader reader, Cancellati
11901191

11911192
// Limit split to 2 splits so we don't accidently split characters in file paths.
11921193
.ToDictionary(
1193-
x => x[0].Trim().Replace("\"", string.Empty).ToLower(),
1194-
x => x[1].Trim().Replace("\"", string.Empty));
1194+
x => x[0].Trim().Replace("\"", string.Empty),
1195+
x => x[1].Trim().Replace("\"", string.Empty),
1196+
StringComparer.OrdinalIgnoreCase);
11951197

11961198
// Here we just want to push all the values that we just retrieved into the
11971199
// parameters dictionary.
@@ -1273,8 +1275,11 @@ private IDictionary<string, string> GetAdditionalParameters(IDictionary<string,
12731275
{
12741276
var wellKnownParameters = new[] { "name", "filename", "content-type", "content-disposition" };
12751277
var additionalParameters = parameters
1276-
.Where(param => !wellKnownParameters.Contains(param.Key))
1277-
.ToDictionary(x => x.Key, x => x.Value);
1278+
.Where(param => !wellKnownParameters.Contains(param.Key, StringComparer.OrdinalIgnoreCase))
1279+
.ToDictionary(
1280+
x => x.Key,
1281+
x => x.Value,
1282+
StringComparer.OrdinalIgnoreCase);
12781283
return additionalParameters;
12791284
}
12801285

0 commit comments

Comments
 (0)