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 84085d5

Browse filesBrowse files
committed
[Routing] Add MONGODB_ID regex to requirement patterns
1 parent 6a029ec commit 84085d5
Copy full SHA for 84085d5

File tree

3 files changed

+28
-0
lines changed
Filter options

3 files changed

+28
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/CHANGELOG.md
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Requirement/Requirement.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum Requirement
2020
public const CATCH_ALL = '.+';
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]+';
23+
public const MONGODB_ID = '[0-9a-f]{24}';
2324
public const POSITIVE_INT = '[1-9][0-9]*';
2425
public const UID_BASE32 = '[0-9A-HJKMNP-TV-Z]{26}';
2526
public const UID_BASE58 = '[1-9A-HJ-NP-Za-km-z]{22}';

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Requirement/RequirementTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ public function testDigitsKO(string $digits)
137137
);
138138
}
139139

140+
/**
141+
* @testWith ["67c8b7d295c70befc3070bf2"]
142+
* ["000000000000000000000000"]
143+
*/
144+
public function testMongoDbIdOK(string $id)
145+
{
146+
$this->assertMatchesRegularExpression(
147+
(new Route('/{id}', [], ['id' => Requirement::MONGODB_ID]))->compile()->getRegex(),
148+
'/'.$id,
149+
);
150+
}
151+
152+
/**
153+
* @testWith ["67C8b7D295C70BEFC3070BF2"]
154+
* ["67c8b7d295c70befc3070bg2"]
155+
* ["67c8b7d295c70befc3070bf2a"]
156+
* ["67c8b7d295c70befc3070bf"]
157+
*/
158+
public function testMongoDbIdKO(string $id)
159+
{
160+
$this->assertDoesNotMatchRegularExpression(
161+
(new Route('/{id}', [], ['id' => Requirement::MONGODB_ID]))->compile()->getRegex(),
162+
'/'.$id,
163+
);
164+
}
165+
140166
/**
141167
* @testWith ["1"]
142168
* ["42"]

0 commit comments

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