Skip to content

Commit

Permalink
Validate version and variant for UUID (#48321)
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro authored Sep 7, 2023
1 parent 9e29910 commit 1591fed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ public static function isUuid($value)
return false;
}

return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0;
if ($value === '00000000-0000-0000-0000-000000000000') {
return true;
}

return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iD', $value) > 0;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ public static function invalidUuidList()
['af6f8cb-c57d-11e1-9b21-0800200c9a66'],
['af6f8cb0c57d11e19b210800200c9a66'],
['ff6f8cb0-c57da-51e1-9b21-0800200c9a66'],
['ff6f8cb0-c57d-11e1-cb21-0800200c9a66'], // Invalid variant
['ff6f8cb0-c57d-61e1-9b21-0800200c9a66'], // Invalid version
];
}

Expand Down

0 comments on commit 1591fed

Please sign in to comment.