Skip to content

Commit

Permalink
Treat empty string as invalid base64-string
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed May 2, 2024
1 parent 7864461 commit 3b93d1e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CustomAssertionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static function stringPlausibleBase64(string $value, string $message = '
$result = false;
} else {
$decoded = base64_decode($value, true);
if ($decoded === false) {
if (empty($decoded)) { // Invalid _or_ empty string
$result = false;
} elseif (base64_encode($decoded) !== $value) {
$result = false;
Expand Down
1 change: 1 addition & 0 deletions tests/Assert/Base64Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function testStringPlausibleBase64(bool $shouldPass, string $name): void
public static function provideBase64(): array
{
return [
'empty' => [false, ''],
'valid' => [true, 'U2ltcGxlU0FNTHBocA=='],
'bogus' => [false, '&*$(#&^@!(^%$'],
'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='],
Expand Down

0 comments on commit 3b93d1e

Please sign in to comment.