Skip to content

Commit 1591fed

Browse files
authored
Validate version and variant for UUID (#48321)
1 parent 9e29910 commit 1591fed

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Illuminate/Support/Str.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,11 @@ public static function isUuid($value)
516516
return false;
517517
}
518518

519-
return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0;
519+
if ($value === '00000000-0000-0000-0000-000000000000') {
520+
return true;
521+
}
522+
523+
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;
520524
}
521525

522526
/**

tests/Support/SupportStrTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,8 @@ public static function invalidUuidList()
965965
['af6f8cb-c57d-11e1-9b21-0800200c9a66'],
966966
['af6f8cb0c57d11e19b210800200c9a66'],
967967
['ff6f8cb0-c57da-51e1-9b21-0800200c9a66'],
968+
['ff6f8cb0-c57d-11e1-cb21-0800200c9a66'], // Invalid variant
969+
['ff6f8cb0-c57d-61e1-9b21-0800200c9a66'], // Invalid version
968970
];
969971
}
970972

0 commit comments

Comments
 (0)