Skip to content

Commit

Permalink
Merge pull request #108 from fiskaltrust/allow-charset-if-quoted
Browse files Browse the repository at this point in the history
Allow quoted charset
  • Loading branch information
volllly authored Oct 13, 2023
2 parents 7beb14c + aa25c10 commit 3002d0c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SemanticVersioning" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="7.0.12" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/fiskaltrust.Launcher/Commands/HostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public async Task<int> InvokeAsync(InvocationContext context)
.WriteTo.GrpcSink(packageConfiguration, processHostService)
.CreateLogger();

System.Text.Encoding.RegisterProvider(new LauncherEncodingProvider());

var builder = Host.CreateDefaultBuilder()
.UseSerilog()
.ConfigureServices(services =>
Expand Down
8 changes: 4 additions & 4 deletions src/fiskaltrust.Launcher/ProcessHost/ProcessHostMonarch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public ProcessHostMonarch(ILogger<ProcessHostMonarch> logger, LauncherConfigurat
"--launcher-configuration", $"\"{Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(launcherConfiguration.Serialize()))}\"",
});

if (Debugger.IsAttached)
{
_process.StartInfo.Arguments += " --debugging";
}
// if (Debugger.IsAttached)
// {
// _process.StartInfo.Arguments += " --debugging";
// }
_process.StartInfo.RedirectStandardInput = true;
_process.StartInfo.RedirectStandardError = true;
_process.StartInfo.RedirectStandardOutput = true;
Expand Down
28 changes: 28 additions & 0 deletions src/fiskaltrust.Launcher/Services/EncodingProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Text;

namespace fiskaltrust.Launcher.Services
{
public class LauncherEncodingProvider : EncodingProvider
{
public override Encoding? GetEncoding(int codepage) => null;

// This EncodingProvider needs to be registered in the plebian processes
// because ASP.NET Core uses the Encoding.GetEncoding(string) method to parse the charset of the Content-Type header.
// According to the http standard (https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.1) the charset may be wrapped in quotes.
// Until this is fixed in ASP.NET we'll need the workaround below.
public override Encoding? GetEncoding(string name)
{
try
{
if ((name.StartsWith('"') && name.EndsWith('"')) || (name.StartsWith('\'') && name.EndsWith('\'')))
{
// This does not lead to an endless recursion, because every time the Encoding.GetEncoding(string) method calls this method either more quotes are trimmed and its recursed or null is returned.
return Encoding.GetEncoding(name.Substring(1, name.Length - 2));
}
}
catch { }

return null;
}
}
}
4 changes: 2 additions & 2 deletions src/fiskaltrust.Launcher/fiskaltrust.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CoreWCF.Http" Version="1.3.2" />
<PackageReference Include="CoreWCF.NetTcp" Version="1.3.2" />
<PackageReference Include="CoreWCF.Http" Version="1.4.1" />
<PackageReference Include="CoreWCF.NetTcp" Version="1.4.1" />
<PackageReference Include="fiskaltrust.interface" Version="1.3.50-rc1" />
<PackageReference Include="fiskaltrust.Middleware.Abstractions" Version="1.3.3" />
<PackageReference Include="fiskaltrust.Middleware.Interface.Client.Soap" Version="1.3.50-rc2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
25 changes: 25 additions & 0 deletions test/fiskaltrust.Launcher.UnitTest/Helpers/EncodingProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text;
using fiskaltrust.Launcher.Common;
using fiskaltrust.Launcher.Services;
using FluentAssertions;
using Xunit;

namespace fiskaltrust.Launcher.UnitTest.Helpers
{
public class LauncherEncodingProviderTest
{
[Fact]
public void GetEncoding_ReturnsUtf8Encoding()
{
var provider = new LauncherEncodingProvider();

Encoding.RegisterProvider(provider);

provider.GetEncoding("\"UTF-8\"").Should().Be(Encoding.UTF8);
provider.GetEncoding("UTF-8").Should().Be(null);

Encoding.GetEncoding("\"UTF-8\"").Should().Be(Encoding.UTF8);
Encoding.GetEncoding("UTF-8").Should().Be(Encoding.UTF8);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0-rc.8",
"version": "2.0.0-rc.9",
"releaseBranches": [
"^refs/tags/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
Expand Down

0 comments on commit 3002d0c

Please sign in to comment.