Skip to content

Commit df460a3

Browse files
[Routing] Add the Requirement::UID_RFC9562 constant
1 parent 8ef329c commit df460a3

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.2
5+
---
6+
7+
* Add the `Requirement::UID_RFC9562` constant to validate UUIDs in the RFC 9562 format
8+
49
7.1
510
---
611

Requirement/Requirement.php

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum Requirement
2424
public const UID_BASE32 = '[0-9A-HJKMNP-TV-Z]{26}';
2525
public const UID_BASE58 = '[1-9A-HJ-NP-Za-km-z]{22}';
2626
public const UID_RFC4122 = '[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}';
27+
public const UID_RFC9562 = self::UID_RFC4122;
2728
public const ULID = '[0-7][0-9A-HJKMNP-TV-Z]{25}';
2829
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}';
2930
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}';

Tests/Requirement/RequirementTest.php

+41-9
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@ public function testUidBase58KO(string $uid)
224224
}
225225

226226
/**
227-
* @testWith ["00000000-0000-0000-0000-000000000000"]
228-
* ["ffffffff-ffff-ffff-ffff-ffffffffffff"]
229-
* ["01802c4e-c409-9f07-863c-f025ca7766a0"]
230-
* ["056654ca-0699-4e16-9895-e60afca090d7"]
227+
* @dataProvider provideUidRfc4122
231228
*/
232229
public function testUidRfc4122OK(string $uid)
233230
{
@@ -238,11 +235,7 @@ public function testUidRfc4122OK(string $uid)
238235
}
239236

240237
/**
241-
* @testWith [""]
242-
* ["foo"]
243-
* ["01802c4e-c409-9f07-863c-f025ca7766a"]
244-
* ["01802c4e-c409-9f07-863c-f025ca7766ag"]
245-
* ["01802c4ec4099f07863cf025ca7766a0"]
238+
* @dataProvider provideUidRfc4122KO
246239
*/
247240
public function testUidRfc4122KO(string $uid)
248241
{
@@ -252,6 +245,45 @@ public function testUidRfc4122KO(string $uid)
252245
);
253246
}
254247

248+
/**
249+
* @dataProvider provideUidRfc4122
250+
*/
251+
public function testUidRfc9562OK(string $uid)
252+
{
253+
$this->assertMatchesRegularExpression(
254+
(new Route('/{uid}', [], ['uid' => Requirement::UID_RFC9562]))->compile()->getRegex(),
255+
'/'.$uid,
256+
);
257+
}
258+
259+
/**
260+
* @dataProvider provideUidRfc4122KO
261+
*/
262+
public function testUidRfc9562KO(string $uid)
263+
{
264+
$this->assertDoesNotMatchRegularExpression(
265+
(new Route('/{uid}', [], ['uid' => Requirement::UID_RFC9562]))->compile()->getRegex(),
266+
'/'.$uid,
267+
);
268+
}
269+
270+
public static function provideUidRfc4122(): iterable
271+
{
272+
yield ['00000000-0000-0000-0000-000000000000'];
273+
yield ['ffffffff-ffff-ffff-ffff-ffffffffffff'];
274+
yield ['01802c4e-c409-9f07-863c-f025ca7766a0'];
275+
yield ['056654ca-0699-4e16-9895-e60afca090d7'];
276+
}
277+
278+
public static function provideUidRfc4122KO(): iterable
279+
{
280+
yield [''];
281+
yield ['foo'];
282+
yield ['01802c4e-c409-9f07-863c-f025ca7766a'];
283+
yield ['01802c4e-c409-9f07-863c-f025ca7766ag'];
284+
yield ['01802c4ec4099f07863cf025ca7766a0'];
285+
}
286+
255287
/**
256288
* @testWith ["00000000000000000000000000"]
257289
* ["7ZZZZZZZZZZZZZZZZZZZZZZZZZ"]

0 commit comments

Comments
 (0)