From bea54e64997bf7c2863e30020dc9839345cbb727 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sat, 21 May 2022 20:01:14 +0200 Subject: [PATCH] [Routing] Add `Requirement::POSITIVE_INT` for common ids and pagination --- src/Symfony/Component/Routing/CHANGELOG.md | 5 +++ .../Routing/Requirement/Requirement.php | 1 + .../Tests/Requirement/RequirementTest.php | 31 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index 62e7cd25f0dc3..fac41b5e638f2 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.2 +--- + + * Add `Requirement::POSITIVE_INT` for common ids and pagination + 6.1 --- diff --git a/src/Symfony/Component/Routing/Requirement/Requirement.php b/src/Symfony/Component/Routing/Requirement/Requirement.php index aa5e464e72603..eefc62e7aae2c 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('/{digits}', [], ['digits' => Requirement::POSITIVE_INT]))->compile()->getRegex(), + '/'.$digits, + ); + } + + /** + * @testWith [""] + * ["0"] + * ["045"] + * ["foo"] + * ["-1"] + * ["3.14"] + */ + public function testPositiveIntKO(string $digits) + { + $this->assertDoesNotMatchRegularExpression( + (new Route('/{digits}', [], ['digits' => Requirement::POSITIVE_INT]))->compile()->getRegex(), + '/'.$digits, + ); + } + /** * @testWith ["00000000000000000000000000"] * ["ZZZZZZZZZZZZZZZZZZZZZZZZZZ"] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy