Content-Length: 331308 | pFad | http://github.com/symfony/symfony/commit/7a2aaaf534b487970cd0f2a1ab965622a95369bc

45 [Routing] Add MONGODB_ID regex to requirement patterns · symfony/symfony@7a2aaaf · GitHub
Skip to content

Commit 7a2aaaf

Browse files
committed
[Routing] Add MONGODB_ID regex to requirement patterns
1 parent 6a029ec commit 7a2aaaf

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Allow aliases and deprecations in `#[Route]` attribute
8+
* Add the `Requirement::MONGODB_ID` constant to validate MongoDB ObjectIDs in hexadecimal format
89

910
7.2
1011
---

src/Symfony/Component/Routing/Requirement/Requirement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum Requirement
2121
public const DATE_YMD = '[0-9]{4}-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|(?<!02-)3[01])'; // YYYY-MM-DD
2222
public const DIGITS = '[0-9]+';
2323
public const POSITIVE_INT = '[1-9][0-9]*';
24+
public const MONGODB_ID = '[0-9a-f]{24}';
2425
public const UID_BASE32 = '[0-9A-HJKMNP-TV-Z]{26}';
2526
public const UID_BASE58 = '[1-9A-HJ-NP-Za-km-z]{22}';
2627
public const UID_RFC4122 = '[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}';

src/Symfony/Component/Routing/Tests/Requirement/RequirementTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ public function testPositiveIntOK(string $digits)
151151
);
152152
}
153153

154+
/**
155+
* @testWith ["67c8b7d295c70befc3070bf2"]
156+
* ["000000000000000000000000"]
157+
*/
158+
public function testMongoID(string $id)
159+
{
160+
$this->assertMatchesRegularExpression(
161+
(new Route('/{id}', [], ['id' => Requirement::MONGODB_ID]))->compile()->getRegex(),
162+
'/'.$id,
163+
);
164+
}
165+
154166
/**
155167
* @testWith [""]
156168
* ["0"]

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/symfony/symfony/commit/7a2aaaf534b487970cd0f2a1ab965622a95369bc

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy