diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index d66f4526d97c5..d21e550f9b57f 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -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 --- diff --git a/src/Symfony/Component/Routing/Requirement/Requirement.php b/src/Symfony/Component/Routing/Requirement/Requirement.php index fdc0009cd2ccf..6de2fbc50d38b 100644 --- a/src/Symfony/Component/Routing/Requirement/Requirement.php +++ b/src/Symfony/Component/Routing/Requirement/Requirement.php @@ -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]|(?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"]