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

Skip to content

Commit 8a8d2a6

Browse files
minor #41803 [Uid] Prevent double validation in Uuid::fromString() with base32 values (fancyweb)
This PR was merged into the 5.3 branch. Discussion ---------- [Uid] Prevent double validation in Uuid::fromString() with base32 values | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follow up to #41693, it should be a little bit faster if we don't validate twice, right? Commits ------- 043ee56 [Uid] Prevent double validation in Uuid::fromString() with base32 values
2 parents a8849cf + 043ee56 commit 8a8d2a6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Symfony/Component/Uid/Ulid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(string $ulid = null)
4343
throw new \InvalidArgumentException(sprintf('Invalid ULID: "%s".', $ulid));
4444
}
4545

46-
$this->uid = strtr($ulid, 'abcdefghjkmnpqrstvwxyz', 'ABCDEFGHJKMNPQRSTVWXYZ');
46+
$this->uid = strtoupper($ulid);
4747
}
4848

4949
public static function isValid(string $ulid): bool

src/Symfony/Component/Uid/Uuid.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public static function fromString(string $uuid): parent
5454
$uuid = substr_replace($uuid, '-', 18, 0);
5555
$uuid = substr_replace($uuid, '-', 23, 0);
5656
} elseif (26 === \strlen($uuid) && Ulid::isValid($uuid)) {
57-
$uuid = (new Ulid($uuid))->toRfc4122();
57+
$ulid = new Ulid('00000000000000000000000000');
58+
$ulid->uid = strtoupper($uuid);
59+
$uuid = $ulid->toRfc4122();
5860
}
5961

6062
if (__CLASS__ !== static::class || 36 !== \strlen($uuid)) {

0 commit comments

Comments
 (0)