Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63e6fb2

Browse files
[Uid] fix checking for valid UUIDs
1 parent a933c3e commit 63e6fb2

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/Symfony/Component/Uid/Uuid.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ class Uuid extends AbstractUid
2222

2323
public function __construct(string $uuid)
2424
{
25-
try {
26-
$type = uuid_type($uuid);
27-
} catch (\ValueError $e) {
28-
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid), 0, $e);
29-
}
25+
$type = uuid_is_valid($uuid) ? uuid_type($uuid) : false;
3026

3127
if (false === $type || \UUID_TYPE_INVALID === $type || (static::TYPE ?: $type) !== $type) {
3228
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
@@ -59,13 +55,11 @@ public static function fromString(string $uuid): parent
5955
return new static($uuid);
6056
}
6157

62-
try {
63-
$type = uuid_type($uuid);
64-
} catch (\ValueError $e) {
65-
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid), 0, $e);
58+
if (!uuid_is_valid($uuid)) {
59+
throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid));
6660
}
6761

68-
switch ($type) {
62+
switch (uuid_type($uuid)) {
6963
case UuidV1::TYPE: return new UuidV1($uuid);
7064
case UuidV3::TYPE: return new UuidV3($uuid);
7165
case UuidV4::TYPE: return new UuidV4($uuid);
@@ -114,7 +108,7 @@ public static function isValid(string $uuid): bool
114108
return uuid_is_valid($uuid);
115109
}
116110

117-
return static::TYPE === uuid_type($uuid);
111+
return uuid_is_valid($uuid) && static::TYPE === uuid_type($uuid);
118112
}
119113

120114
public function toBinary(): string

0 commit comments

Comments
 (0)