mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
fix: update validation to support versions 6 & 7
This commit is contained in:
@@ -109,6 +109,7 @@ interface FieldsInterface extends BaseFieldsInterface
|
||||
* 4. Randomly generated UUID
|
||||
* 5. Name-based UUID hashed with SHA-1
|
||||
* 6. Reordered time UUID
|
||||
* 7. Unix Epoch time UUID
|
||||
*
|
||||
* This returns `null` if the UUID is not an RFC 4122 variant, since version
|
||||
* is only meaningful for this variant.
|
||||
|
||||
@@ -28,7 +28,7 @@ use function str_replace;
|
||||
final class Validator implements ValidatorInterface
|
||||
{
|
||||
private const VALID_PATTERN = '\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-'
|
||||
. '[1-5]{1}[0-9A-Fa-f]{3}-[ABab89]{1}[0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z';
|
||||
. '[1-7][0-9A-Fa-f]{3}-[ABab89][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}\z';
|
||||
|
||||
/**
|
||||
* @psalm-return non-empty-string
|
||||
@@ -43,7 +43,8 @@ final class Validator implements ValidatorInterface
|
||||
public function validate(string $uuid): bool
|
||||
{
|
||||
$uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid);
|
||||
$uuid = strtolower($uuid);
|
||||
|
||||
return $uuid === Uuid::NIL || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid);
|
||||
return $uuid === Uuid::NIL || $uuid === Uuid::MAX || preg_match('/' . self::VALID_PATTERN . '/Dms', $uuid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user