Skip to content

Commit

Permalink
Enable decoding of unpadded base64 strings (#187)
Browse files Browse the repository at this point in the history
Closes #178

Co-authored-by: Regenhardt Marlon <[email protected]>
  • Loading branch information
Regenhardt and sf-mregenhardt authored Mar 26, 2022
1 parent 065ad1a commit d2ac6b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ private async Task<string> DecodeBase64DataAsync(string? data)
return string.Empty;
}

int remainder = data!.Length % 4;
if (remainder > 0)
{
int padding = 4 - remainder;
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 d2ac6b7

Please sign in to comment.