mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Throw InvalidArgumentException
instead of TypeError
for decoding an empty string when using Base62::decode
. (#6415)
Co-authored-by: Lu Fei <52o@qq52o.cn> Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
5f3d52f3e3
commit
c1b7d6ae42
@ -1,5 +1,9 @@
|
||||
# v3.1.4 - TBD
|
||||
|
||||
## Optimized
|
||||
|
||||
- [#6415](https://github.com/hyperf/hyperf/pull/6415) Throw `InvalidArgumentException` instead of `TypeError` for decoding an empty string when using `Base62::decode`.
|
||||
|
||||
# v3.1.3 - 2023-12-21
|
||||
|
||||
## Fixed
|
||||
|
@ -32,7 +32,7 @@ class Base62
|
||||
|
||||
public static function decode(string $data): int
|
||||
{
|
||||
if (strlen($data) !== strspn($data, self::CHARS)) {
|
||||
if ($data === '' || strlen($data) !== strspn($data, self::CHARS)) {
|
||||
throw new InvalidArgumentException('The decode data contains content outside of CHARS.');
|
||||
}
|
||||
return array_reduce(array_map(function ($character) {
|
||||
|
@ -33,5 +33,10 @@ class Base62Test extends TestCase
|
||||
} catch (Throwable $exception) {
|
||||
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
|
||||
}
|
||||
try {
|
||||
Base62::decode('');
|
||||
} catch (Throwable $exception) {
|
||||
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user