Change UUIdv4 validation to properly check for version 4 UUIDs
This commit is contained in:
@@ -56,6 +56,8 @@ print "UNIQU ID LONG : " . Uids::uniqIdLong() . "<br>";
|
|||||||
$uuidv4 = Uids::uuidv4();
|
$uuidv4 = Uids::uuidv4();
|
||||||
if (!Uids::validateUuuidv4($uuidv4)) {
|
if (!Uids::validateUuuidv4($uuidv4)) {
|
||||||
print "Invalid UUIDv4: " . $uuidv4 . "<br>";
|
print "Invalid UUIDv4: " . $uuidv4 . "<br>";
|
||||||
|
} else {
|
||||||
|
print "Valid UUIDv4: " . $uuidv4 . "<br>";
|
||||||
}
|
}
|
||||||
if (!Uids::validateUuuidv4("foobar")) {
|
if (!Uids::validateUuuidv4("foobar")) {
|
||||||
print "Invalid UUIDv4: hard coded<Br>";
|
print "Invalid UUIDv4: hard coded<Br>";
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class Uids
|
|||||||
*/
|
*/
|
||||||
public static function validateUuuidv4(string $uuidv4): bool
|
public static function validateUuuidv4(string $uuidv4): bool
|
||||||
{
|
{
|
||||||
if (!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/", $uuidv4)) {
|
if (!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i", $uuidv4)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user