From e3e9179f275a44b8e462816d1c65958ff90c4c96 Mon Sep 17 00:00:00 2001 From: hubipe Date: Sat, 29 Jan 2022 20:05:59 +0100 Subject: [PATCH] LazyUuidFromString for valid UUIDs in uppercase (#401) --- src/Uuid.php | 3 ++- tests/UuidTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Uuid.php b/src/Uuid.php index 945480b..5f0922b 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -476,10 +476,11 @@ class Uuid implements UuidInterface */ public static function fromString(string $uuid): UuidInterface { + $uuid = strtolower($uuid); if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) { assert($uuid !== ''); - return new LazyUuidFromString(strtolower($uuid)); + return new LazyUuidFromString($uuid); } return self::getFactory()->fromString($uuid); diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 29f1761..2ebac1d 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -132,6 +132,17 @@ class UuidTest extends TestCase Uuid::fromString(''); } + public function testFromStringUppercase(): void + { + $uuid = Uuid::fromString('FF6F8CB0-C57D-11E1-9B21-0800200C9A66'); + $this->assertSame('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); + } + + public function testFromStringLazyUuidFromUppercase(): void + { + $this->assertInstanceOf(LazyUuidFromString::class, Uuid::fromString('FF6F8CB0-C57D-11E1-9B21-0800200C9A66')); + } + public function testGetBytes(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');