8000 [Routing] Add the `Requirement::UID_RFC9562` constant by alexandre-daubois · Pull Request #58336 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Add the Requirement::UID_RFC9562 constant #58336

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.2
---

* Add the `Requirement::UID_RFC9562` constant to validate UUIDs in the RFC 9562 format

7.1
---

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Routing/Requirement/Requirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum Requirement
public const UID_BASE32 = '[0-9A-HJKMNP-TV-Z]{26}';
public const UID_BASE58 = '[1-9A-HJ-NP-Za-km-z]{22}';
public const UID_RFC4122 = '[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}';
public const UID_RFC9562 = self::UID_RFC4122;
public const ULID = '[0-7][0-9A-HJKMNP-TV-Z]{25}';
public const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[13-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}';
public const UUID_V1 = '[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ public function testUidBase58KO(string $uid)
}

/**
* @testWith ["00000000-0000-0000-0000-000000000000"]
* ["ffffffff-ffff-ffff-ffff-ffffffffffff"]
* ["01802c4e-c409-9f07-863c-f025ca7766a0"]
* ["056654ca-0699-4e16-9895-e60afca090d7"]
* @dataProvider provideUidRfc4122
*/
public function testUidRfc4122OK(string $uid)
{
Expand All @@ -238,11 +235,7 @@ public function testUidRfc4122OK(string $uid)
}

/**
* @testWith [""]
* ["foo"]
* ["01802c4e-c409-9f07-863c-f025ca7766a"]
* ["01802c4e-c409-9f07-863c-f025ca7766ag"]
* ["01802c4ec4099f07863cf025ca7766a0"]
* @dataProvider provideUidRfc4122KO
*/
public function testUidRfc4122KO(string $uid)
{
Expand All @@ -252,6 +245,45 @@ public function testUidRfc4122KO(string $uid)
);
}

/**
* @dataProvider provideUidRfc4122
*/
public function testUidRfc9562OK(string $uid)
{
$this->assertMatchesRegularExpression(
(new Route('/{uid}', [], ['uid' => Requirement::UID_RFC9562]))->compile()->getRegex(),
'/'.$uid,
);
}

/**
* @dataProvider provideUidRfc4122KO
*/
public function testUidRfc9562KO(string $uid)
{
$this->assertDoesNotMatchRegularExpression(
(new Route('/{uid}', [], ['uid' => Requirement::UID_RFC9562]))->compile()->getRegex(),
'/'.$uid,
);
}

public static function provideUidRfc4122(): iterable
{
yield ['00000000-0000-0000-0000-000000000000'];
yield ['ffffffff-ffff-ffff-ffff-ffffffffffff'];
yield ['01802c4e-c409-9f07-863c-f025ca7766a0'];
yield ['056654ca-0699-4e16-9895-e60afca090d7'];
}

public static function provideUidRfc4122KO(): iterable
{
yield [''];
yield ['foo'];
yield ['01802c4e-c409-9f07-863c-f025ca7766a'];
yield ['01802c4e-c409-9f07-863c-f025ca7766ag'];
yield ['01802c4ec4099f07863cf025ca7766a0'];
}

/**
* @testWith ["00000000000000000000000000"]
* ["7ZZZZZZZZZZZZZZZZZZZZZZZZZ"]
Expand Down
Loading
0