Skip to content

Commit

Permalink
minor #41803 [Uid] Prevent double validation in Uuid::fromString() wi…
Browse files Browse the repository at this point in the history
…th 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
  • Loading branch information
nicolas-grekas committed Jun 23, 2021
2 parents a8849cf + 043ee56 commit 8a8d2a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Uid/Ulid.php
Expand Up @@ -43,7 +43,7 @@ public function __construct(string $ulid = null)
throw new \InvalidArgumentException(sprintf('Invalid ULID: "%s".', $ulid));
}

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

public static function isValid(string $ulid): bool
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Uid/Uuid.php
Expand Up @@ -54,7 +54,9 @@ public static function fromString(string $uuid): parent
$uuid = substr_replace($uuid, '-', 18, 0);
$uuid = substr_replace($uuid, '-', 23, 0);
} elseif (26 === \strlen($uuid) && Ulid::isValid($uuid)) {
$uuid = (new Ulid($uuid))->toRfc4122();
$ulid = new Ulid('00000000000000000000000000');
$ulid->uid = strtoupper($uuid);
$uuid = $ulid->toRfc4122();
}

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

0 comments on commit 8a8d2a6

Please sign in to comment.