mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Merge pull request #383 from cs278/empty-string
Fix soft BC break with `Uuid::fromString()` signature
This commit is contained in:
+4
-1
@@ -24,6 +24,7 @@ use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
use Ramsey\Uuid\Type\Integer as IntegerObject;
|
||||
|
||||
use function assert;
|
||||
use function bin2hex;
|
||||
use function preg_match;
|
||||
use function str_replace;
|
||||
@@ -436,7 +437,7 @@ class Uuid implements UuidInterface
|
||||
/**
|
||||
* Creates a UUID from the string standard representation
|
||||
*
|
||||
* @param non-empty-string $uuid A hexadecimal string
|
||||
* @param string $uuid A hexadecimal string
|
||||
*
|
||||
* @return UuidInterface A UuidInterface instance created from a hexadecimal
|
||||
* string representation
|
||||
@@ -452,6 +453,8 @@ class Uuid implements UuidInterface
|
||||
public static function fromString(string $uuid): UuidInterface
|
||||
{
|
||||
if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
|
||||
assert($uuid !== '');
|
||||
|
||||
return new LazyUuidFromString(strtolower($uuid));
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,14 @@ class UuidTest extends TestCase
|
||||
$this->assertSame('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString());
|
||||
}
|
||||
|
||||
public function testFromStringWithEmptyString(): void
|
||||
{
|
||||
$this->expectException(InvalidUuidStringException::class);
|
||||
$this->expectExceptionMessage('Invalid UUID string: ');
|
||||
|
||||
Uuid::fromString('');
|
||||
}
|
||||
|
||||
public function testGetBytes(): void
|
||||
{
|
||||
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
|
||||
|
||||
Reference in New Issue
Block a user