Skip to content

Commit

Permalink
Merge branch 'release/0.108.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed May 26, 2024
2 parents 87a1e84 + eb52223 commit 961e63e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Logzio.DotNet.NLog" Version="1.1.0" />
<PackageReference Include="Logzio.DotNet.NLog" Version="1.1.1" />
<PackageReference Include="Microsoft.ApplicationInsights.NLogTarget" Version="2.22.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />

<!-- This is a workaround for the problem described here: https://github.com/logzio/logzio-dotnet/issues/72 -->
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Source/StrongGrid.UnitTests/StrongGrid.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 4 additions & 3 deletions Source/StrongGrid/StrongGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HttpMultipartParser" Version="8.3.0" />
<PackageReference Include="HttpMultipartParser" Version="8.4.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="MimeKitLite" Version="4.4.0" />
<PackageReference Include="Pathoschild.Http.FluentClient" Version="4.3.0" />
<PackageReference Include="MimeKitLite" Version="4.6.0" />
<PackageReference Include="Pathoschild.Http.FluentClient" Version="4.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="UTF.Unknown" Version="2.5.1" />
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
Expand Down
26 changes: 24 additions & 2 deletions Source/StrongGrid/Utilities/SendGridMultipartFormDataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using UtfUnknown;

namespace StrongGrid.Utilities
{
Expand Down Expand Up @@ -62,6 +63,23 @@ private static SendGridMultipartFormDataParser ConvertToSendGridParser(Multipart
{
// Get the encoding specified by SendGrid for this parameter
encodings.TryGetValue(parameter.Name, out Encoding encoding);

// If necessary, determine the encoding by looking at the content
if (encoding == null && (parameter.Data?.Any() ?? false))
{
// Concatenate the lines of data.
// Normally you would append a NewLine after each line but it's not necessary for this particular instance.
// Besides, we don't know (yet) what encoding to use to convert the NewLine characters into bytes.
var parameterData = parameter.Data
.SelectMany(d => d)
.ToArray();

// Try to detect the encoding based on the content
var result = CharsetDetector.DetectFromBytes(parameterData);
encoding = result?.Detected?.Encoding;
}

// When all else fails, fallback to UTF8
encoding ??= Encoding.UTF8;

sendGridParser._parameters.Add(new ParameterPart(parameter.Name, parameter.ToString(encoding)));
Expand All @@ -79,7 +97,7 @@ private static Encoding GetEncodingFromName(string encodingName)
{
return Encoding.GetEncoding(encodingName);
}
catch (ArgumentException)
catch
{
// ArgumentException is thrown when an "unusual" code page was used to encode a section of the email
// For example: {"to":"UTF-8","subject":"UTF-8","from":"UTF-8","text":"iso-8859-10"}
Expand All @@ -88,7 +106,11 @@ private static Encoding GetEncodingFromName(string encodingName)
// perfect because UTF-8 may or may not be able to handle all the encoded characters, but it's better
// than simply erroring out.
// See https://github.com/Jericho/StrongGrid/issues/341 for discussion.
return Encoding.UTF8;

// April 2024: return a null value instead of defaulting to UTF8 when the encoding name is invalid.
// This will allow us to subsequently use the actual content to attempt to determine which encoding
// was used to encode it.
return null;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#tool dotnet:?package=GitVersion.Tool&version=5.12.0
#tool dotnet:?package=coveralls.net&version=4.0.1
#tool nuget:https://f.feedz.io/jericho/jericho/nuget/?package=GitReleaseManager&version=0.17.0-collaborators0004
#tool nuget:?package=ReportGenerator&version=5.2.4
#tool nuget:?package=xunit.runner.console&version=2.7.0
#tool nuget:?package=CodecovUploader&version=0.7.2
#tool nuget:?package=ReportGenerator&version=5.3.0
#tool nuget:?package=xunit.runner.console&version=2.8.1
#tool nuget:?package=CodecovUploader&version=0.7.3

// Install addins.
#addin nuget:?package=Cake.Coveralls&version=1.1.0
#addin nuget:?package=Cake.Git&version=4.0.0
#addin nuget:?package=Cake.Codecov&version=1.0.1
#addin nuget:?package=Cake.Codecov&version=3.0.0


///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.203",
"version": "8.0.300",
"rollForward": "patch",
"allowPrerelease": false
}
Expand Down

0 comments on commit 961e63e

Please sign in to comment.