Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Mar 29, 2024
1 parent 04fe762 commit f6f72da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Base32/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class Base32
private function __construct(string $alphabet, string $padding)
{
if (1 !== strlen($padding) || false !== strpos(self::RESERVED_CHARACTERS, $padding)) {
throw new ValueError('The padding character must be a non reserved single byte character.');
throw new ValueError('The padding character must be a non-reserved single byte character.');
}

if (self::ALPHABET_SIZE !== strlen($alphabet)) {
Expand Down Expand Up @@ -155,7 +155,6 @@ public function decode(string $encoded, bool $strict = false): string
$bitLen = 5;
$length = strlen($encoded);
$decoded = '';

do {
if (!isset($val)) {
$index = $encoded[$offset];
Expand Down
8 changes: 4 additions & 4 deletions src/Base32/Base32Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,28 @@ public static function invalidDecodingSequence(): iterable

yield 'the padding character is different than one byte' => [
'sequence' => 'A',
'message' => 'The padding character must be a non reserved single byte character.',
'message' => 'The padding character must be a non-reserved single byte character.',
'alphabet' => PHP_BASE32_ASCII,
'padding' => 'yo',
];

yield 'the padding character can not contain "\r"' => [
'sequence' => 'A',
'message' => 'The padding character must be a non reserved single byte character.',
'message' => 'The padding character must be a non-reserved single byte character.',
'alphabet' => PHP_BASE32_ASCII,
'padding' => "\r",
];

yield 'the padding character can not contain "\n"' => [
'sequence' => 'A',
'message' => 'The padding character must be a non reserved single byte character.',
'message' => 'The padding character must be a non-reserved single byte character.',
'alphabet' => PHP_BASE32_ASCII,
'padding' => "\n",
];

yield 'the padding character can not contain "\t"' => [
'sequence' => 'A',
'message' => 'The padding character must be a non reserved single byte character.',
'message' => 'The padding character must be a non-reserved single byte character.',
'alphabet' => PHP_BASE32_ASCII,
'padding' => "\t",
];
Expand Down

0 comments on commit f6f72da

Please sign in to comment.