8000 feature #46430 [Routing] Add `Requirement::POSITIVE_INT` for common i… · symfony/symfony@a10071b · GitHub
[go: up one dir, main page]

Skip to content

Commit a10071b

Browse files
feature #46430 [Routing] Add Requirement::POSITIVE_INT for common ids and pagination (HeahDude)
This PR was merged into the 6.2 branch. Discussion ---------- [Routing] Add `Requirement::POSITIVE_INT` for common ids and pagination | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #45528 | License | MIT | Doc PR | ~ I targeted 6.1 because it's not yet released, should I rebase onto 6.2? ping `@fancyweb` :) Commits ------- bea54e6 [Routing] Add `Requirement::POSITIVE_INT` for common ids and pagination
2 parents 7e485db + bea54e6 commit a10071b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.2
5+
---
6+
7+
* Add `Requirement::POSITIVE_INT` for common ids and pagination
8+
49
6.1
510
---
611

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

Lines 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 POSITIVE_INT = '[1-9][0-9]*';
2324
public const UID_BASE32 = '[0-9A-HJKMNP-TV-Z]{26}';
2425
public const UID_BASE58 = '[1-9A-HJ-NP-Za-km-z]{22}';
2526
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function testDateYmdKO(string $date)
109109

110110
/**
111111
* @testWith ["0"]
112+
* ["012"]
112113
* ["1"]
113114
* ["42"]
114115
* ["42198"]
@@ -136,6 +137,36 @@ public function testDigitsKO(string $digits)
136137
);
137138
}
138139

140+
/**
141+
* @testWith ["1"]
142+
* ["42"]
143+
* ["42198"]
144+
* ["999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"]
145+
*/
146+
public function testPositiveIntOK(string $digits)
147+
{
148+
$this->assertMatchesRegularExpression(
149+
(new Route('/{digits}', [], ['digits' => Requirement::POSITIVE_INT]))->compile()->getRegex(),
150+
'/'.$digits,
151+
);
152+
}
153+
154+
/**
155+
* @testWith [""]
156+
* ["0"]
157+
* ["045"]
158+
* ["foo"]
159+
* ["-1"]
160+
* ["3.14"]
161+
*/
162+
public function testPositiveIntKO(string $digits)
163+
{
164+
$this->assertDoesNotMatchRegularExpression(
165+
(new Route('/{digits}', [], ['digits' => Requirement::POSITIVE_INT]))->compile()->getRegex(),
166+
'/'.$digits,
167+
);
168+
}
169+
139170
/**
140171
* @testWith ["00000000000000000000000000"]
141172
* ["ZZZZZZZZZZZZZZZZZZZZZZZZZZ"]

0 commit comments

Comments
 (0)
0