mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
UUID: properly account for garbage inputs which aren't valid hexadecimal
this would previously throw a TypeError and crash.
This commit is contained in:
parent
e3ebf8bb61
commit
ccad97727f
@ -61,7 +61,12 @@ class UUID{
|
|||||||
* Creates an UUID from an hexadecimal representation
|
* Creates an UUID from an hexadecimal representation
|
||||||
*/
|
*/
|
||||||
public static function fromString(string $uuid, int $version = null) : UUID{
|
public static function fromString(string $uuid, int $version = null) : UUID{
|
||||||
return self::fromBinary(hex2bin(str_replace("-", "", trim($uuid))), $version);
|
//TODO: should we be stricter about the notation (8-4-4-4-12)?
|
||||||
|
$binary = @hex2bin(str_replace("-", "", trim($uuid)));
|
||||||
|
if($binary === false){
|
||||||
|
throw new \InvalidArgumentException("Invalid hex string UUID representation");
|
||||||
|
}
|
||||||
|
return self::fromBinary($binary, $version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user