Skip to content

Commit

Permalink
Enable decoding of unpadded base64 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sf-mregenhardt committed Mar 21, 2022
1 parent f438f1c commit 4612bfe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ private async Task<string> DecodeBase64DataAsync(string? data)
return string.Empty;
}

int padding = data!.Length % 4;
if (padding > 0)
{
data = data.PadRight(data.Length + padding, '=');
}

await TaskScheduler.Default;
string? decoded = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ await ThreadHelper.RunOnUIThreadAsync(() =>
[DataRow("", "")]
[DataRow(" ", "")]
[DataRow("SGVsbG8gVGhlcmU=", "Hello There")]
[DataRow("SGVsbG8gVGhlcmU", "Hello There")]
public async Task DecodeAsync(string input, string expectedResult)
{
Base64EncoderDecoderToolViewModel viewModel = ExportProvider.Import<Base64EncoderDecoderToolViewModel>();
Expand Down

0 comments on commit 4612bfe

Please sign in to comment.