Skip to content

Commit

Permalink
Merge branch 'release/7.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Oct 30, 2022
2 parents 046fab5 + 2a37e57 commit f95dc3e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "2.2.0",
"version": "2.3.0",
"commands": [
"dotnet-cake"
]
Expand Down
Expand Up @@ -113,7 +113,9 @@ private bool ValidateFiles(MultipartFormDataParser parser)
if (expectedFile.ContentDisposition != actualFile.ContentDisposition) return false;

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

// Read the data from the files and see if it's the same
if (expectedFile.Data.CanSeek && expectedFile.Data.Position != 0) expectedFile.Data.Position = 0;
Expand Down
3 changes: 2 additions & 1 deletion Source/HttpMultipartParser/FilePart.cs
Expand Up @@ -24,6 +24,7 @@
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
Expand Down Expand Up @@ -97,7 +98,7 @@ public FilePart(string name, string fileName, Stream data, IDictionary<string, s
Data = data;
ContentType = contentType;
ContentDisposition = contentDisposition;
AdditionalProperties = new ReadOnlyDictionary<string, string>(additionalProperties ?? new Dictionary<string, string>());
AdditionalProperties = new ReadOnlyDictionary<string, string>(additionalProperties ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase));
}

#endregion
Expand Down
29 changes: 19 additions & 10 deletions Source/HttpMultipartParser/StreamingMultipartFormDataParser.cs
Expand Up @@ -364,8 +364,10 @@ private static async Task<string> DetectBoundaryAsync(RebufferableBinaryReader r
/// </summary>
/// <param name="parameters">The section parameters.</param>
/// <returns>true if the section contains a file, false otherwise.</returns>
private bool IsFilePart(IDictionary<string, string> parameters!!)
private bool IsFilePart(IDictionary<string, string> parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));

// A section without any parameter is invalid. It is very likely to contain just a bunch of blank lines.
if (parameters.Count == 0) return false;

Expand All @@ -388,8 +390,10 @@ private bool IsFilePart(IDictionary<string, string> parameters!!)
/// </summary>
/// <param name="parameters">The section parameters.</param>
/// <returns>true if the section contains a data parameter, false otherwise.</returns>
private bool IsParameterPart(IDictionary<string, string> parameters!!)
private bool IsParameterPart(IDictionary<string, string> parameters)
{
if (parameters == null) throw new ArgumentNullException(nameof(parameters));

// A section without any parameter is invalid. It is very likely to contain just a bunch of blank lines.
if (parameters.Count == 0) return false;

Expand Down Expand Up @@ -1052,7 +1056,7 @@ private void ParseSection(RebufferableBinaryReader reader)
// in the case of single file uploads. Multi-file uploads have Content-Disposition: file according
// to the spec however in practise it seems that multiple files will be represented by
// multiple Content-Disposition: form-data files.
var parameters = new Dictionary<string, string>();
var parameters = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

string line = reader.ReadLine();
while (line != string.Empty)
Expand Down Expand Up @@ -1087,8 +1091,9 @@ private void ParseSection(RebufferableBinaryReader reader)

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

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

string line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);
while (line != string.Empty)
Expand Down Expand Up @@ -1186,8 +1191,9 @@ private async Task ParseSectionAsync(RebufferableBinaryReader reader, Cancellati

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

// Here we just want to push all the values that we just retrieved into the
// parameters dictionary.
Expand Down Expand Up @@ -1269,8 +1275,11 @@ private IEnumerable<string> SplitBySemicolonIgnoringSemicolonsInQuotes(string li
{
var wellKnownParameters = new[] { "name", "filename", "content-type", "content-disposition" };
var additionalParameters = parameters
.Where(param => !wellKnownParameters.Contains(param.Key))
.ToDictionary(x => x.Key, x => x.Value);
.Where(param => !wellKnownParameters.Contains(param.Key, StringComparer.OrdinalIgnoreCase))
.ToDictionary(
x => x.Key,
x => x.Value,
StringComparer.OrdinalIgnoreCase);
return additionalParameters;
}

Expand Down
6 changes: 3 additions & 3 deletions build.cake
@@ -1,9 +1,9 @@
// Install tools.
#tool dotnet:?package=GitVersion.Tool&version=5.10.3
#tool dotnet:?package=coveralls.net&version=4.0.0
#tool dotnet:?package=coveralls.net&version=4.0.1
#tool nuget:?package=GitReleaseManager&version=0.13.0
#tool nuget:?package=ReportGenerator&version=5.1.9
#tool nuget:?package=xunit.runner.console&version=2.4.1
#tool nuget:?package=ReportGenerator&version=5.1.10
#tool nuget:?package=xunit.runner.console&version=2.4.2
#tool nuget:?package=Codecov&version=1.13.0

// Install addins.
Expand Down
2 changes: 1 addition & 1 deletion global.json
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.301",
"version": "6.0.401",
"rollForward": "latestFeature"
}
}

0 comments on commit f95dc3e

Please sign in to comment.