-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from fiskaltrust/allow-charset-if-quoted
Allow quoted charset
- Loading branch information
Showing
9 changed files
with
73 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/fiskaltrust.Launcher.UnitTest/Helpers/EncodingProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters