From adc079056d52e8dd51df4547ad535e55a0221901 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Wed, 6 Sep 2023 12:44:47 -0400 Subject: [PATCH] Validate version and variant for UUID --- src/Illuminate/Support/Str.php | 6 +++++- tests/Support/SupportStrTest.php | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index bb5a331accc3..da9540e29ede 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -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; } /** diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 8a2e7979f70c..c455c64d65be 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -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 ]; }