Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f84170a

Browse filesBrowse files
[Serializer][Uid] Add the Uuid::FORMAT_RFC_9562 and UidNormalizer::NORMALIZATION_FORMAT_RFC9562 constants
1 parent 44395ab commit f84170a
Copy full SHA for f84170a

File tree

5 files changed

+18
-9
lines changed
Filter options

5 files changed

+18
-9
lines changed

‎src/Symfony/Component/Serializer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Deprecate `CsvEncoderContextBuilder::withEscapeChar()` method
99
* Add `SnakeCaseToCamelCaseNameConverter`
1010
* Support subclasses of `\DateTime` and `\DateTimeImmutable` for denormalization
11+
* Add the `UidNormalizer::NORMALIZATION_FORMAT_RFC9562` constant
1112

1213
7.1
1314
---

‎src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class UidNormalizer implements NormalizerInterface, DenormalizerInterface
2323
public const NORMALIZATION_FORMAT_BASE58 = 'base58';
2424
public const NORMALIZATION_FORMAT_BASE32 = 'base32';
2525
public const NORMALIZATION_FORMAT_RFC4122 = 'rfc4122';
26+
public const NORMALIZATION_FORMAT_RFC9562 = self::NORMALIZATION_FORMAT_RFC4122;
2627
public const NORMALIZATION_FORMATS = [
2728
self::NORMALIZATION_FORMAT_CANONICAL,
2829
self::NORMALIZATION_FORMAT_BASE58,

‎src/Symfony/Component/Uid/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Make `AbstractUid` implement `Ds\Hashable` if available
88
* Add support for binary, base-32 and base-58 representations in `Uuid::isValid()`
9+
* Add the `Uuid::FORMAT_RFC_9562` constant to validate UUIDs in the RFC 9562 format
910

1011
7.1
1112
---

‎src/Symfony/Component/Uid/Tests/UuidTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Tests/UuidTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ public function testIsValidWithVariousFormat()
237237
$this->assertFalse(Uuid::isValid($uuid->toBinary(), Uuid::FORMAT_RFC_4122));
238238
$this->assertTrue(Uuid::isValid($uuid->toRfc4122(), Uuid::FORMAT_RFC_4122));
239239

240+
$this->assertFalse(Uuid::isValid($uuid->toBase32(), Uuid::FORMAT_RFC_9562));
241+
$this->assertFalse(Uuid::isValid($uuid->toBase58(), Uuid::FORMAT_RFC_9562));
242+
$this->assertFalse(Uuid::isValid($uuid->toBinary(), Uuid::FORMAT_RFC_9562));
243+
$this->assertTrue(Uuid::isValid($uuid->toRfc4122(), Uuid::FORMAT_RFC_9562));
244+
240245
$this->assertTrue(Uuid::isValid($uuid->toBase32(), Uuid::FORMAT_ALL));
241246
$this->assertTrue(Uuid::isValid($uuid->toBase58(), Uuid::FORMAT_ALL));
242247
$this->assertTrue(Uuid::isValid($uuid->toBinary(), Uuid::FORMAT_ALL));

‎src/Symfony/Component/Uid/Uuid.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Uuid.php
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Uuid extends AbstractUid
2727
public const FORMAT_BASE_32 = 1 << 1;
2828
public const FORMAT_BASE_58 = 1 << 2;
2929
public const FORMAT_RFC_4122 = 1 << 3;
30+
public const FORMAT_RFC_9562 = self::FORMAT_RFC_4122;
3031
public const FORMAT_ALL = -1;
3132

3233
protected const TYPE = 0;
@@ -50,7 +51,7 @@ public function __construct(string $uuid, bool $checkVariant = false)
5051

5152
public static function fromString(string $uuid): static
5253
{
53-
$uuid = self::transformToRfc4122($uuid, self::FORMAT_ALL);
54+
$uuid = self::transformToRfc9562($uuid, self::FORMAT_ALL);
5455

5556
if (__CLASS__ !== static::class || 36 !== \strlen($uuid)) {
5657
return new static($uuid);
@@ -124,15 +125,15 @@ final public static function v8(string $uuid): UuidV8
124125
/**
125126
* @param int-mask-of<Uuid::FORMAT_*> $format
126127
*/
127-
public static function isValid(string $uuid /* , int $format = self::FORMAT_RFC_4122 */): bool
128+
public static function isValid(string $uuid /* , int $format = self::FORMAT_RFC_9562 */): bool
128129
{
129-
$format = 1 < \func_num_args() ? func_get_arg(1) : self::FORMAT_RFC_4122;
130+
$format = 1 < \func_num_args() ? func_get_arg(1) : self::FORMAT_RFC_9562;
130131

131-
if (36 === \strlen($uuid) && !($format & self::FORMAT_RFC_4122)) {
132+
if (36 === \strlen($uuid) && !($format & self::FORMAT_RFC_9562)) {
132133
return false;
133134
}
134135

135-
if (false === $uuid = self::transformToRfc4122($uuid, $format)) {
136+
if (false === $uuid = self::transformToRfc9562($uuid, $format)) {
136137
return false;
137138
}
138139

@@ -188,13 +189,13 @@ private static function format(string $uuid, string $version): string
188189
}
189190

190191
/**
191-
* Transforms a binary string, a base-32 string or a base-58 string to a RFC4122 string.
192+
* Transforms a binary string, a base-32 string or a base-58 string to a RFC9562 string.
192193
*
193194
* @param int-mask-of<Uuid::FORMAT_*> $format
194195
*
195-
* @return string|false The RFC4122 string or false if the format doesn't match the input
196+
* @return string|false The RFC9562 string or false if the format doesn't match the input
196197
*/
197-
private static function transformToRfc4122(string $uuid, int $format): string|false
198+
private static function transformToRfc9562(string $uuid, int $format): string|false
198199
{
199200
$inputUuid = $uuid;
200201
$fromBase58 = false;
@@ -217,7 +218,7 @@ private static function transformToRfc4122(string $uuid, int $format): string|fa
217218
$uuid = $ulid->toRfc4122();
218219
}
219220

220-
if ($inputUuid === $uuid && !($format & self::FORMAT_RFC_4122)) {
221+
if ($inputUuid === $uuid && !($format & self::FORMAT_RFC_9562)) {
221222
// input format doesn't match the input string
222223
return false;
223224
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.