Skip to content
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
1 change: 1 addition & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

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

7.2
---
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 @@ -20,6 +20,7 @@ enum Requirement
public const CATCH_ALL = '.+';
public const DATE_YMD = '[0-9]{4}-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|(?<!02-)3[01])'; // YYYY-MM-DD
public const DIGITS = '[0-9]+';
public const MONGODB_ID = '[0-9a-f]{24}';
public const POSITIVE_INT = '[1-9][0-9]*';
public const UID_BASE32 = '[0-9A-HJKMNP-TV-Z]{26}';
public const UID_BASE58 = '[1-9A-HJ-NP-Za-km-z]{22}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ public function testDigitsKO(string $digits)
);
}

/**
* @testWith ["67c8b7d295c70befc3070bf2"]
* ["000000000000000000000000"]
*/
public function testMongoDbIdOK(string $id)
{
$this->assertMatchesRegularExpression(
(new Route('/{id}', [], ['id' => Requirement::MONGODB_ID]))->compile()->getRegex(),
'/'.$id,
);
}

/**
* @testWith ["67C8b7D295C70BEFC3070BF2"]
* ["67c8b7d295c70befc3070bg2"]
* ["67c8b7d295c70befc3070bf2a"]
* ["67c8b7d295c70befc3070bf"]
*/
public function testMongoDbIdKO(string $id)
{
$this->assertDoesNotMatchRegularExpression(
(new Route('/{id}', [], ['id' => Requirement::MONGODB_ID]))->compile()->getRegex(),
'/'.$id,
);
}

/**
* @testWith ["1"]
* ["42"]
Expand Down
Loading