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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Add `Requirement::POSITIVE_INT` for common ids and pagination

6.1
---

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 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}';
public const UID_RFC4122 = '[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function testDateYmdKO(string $date)

/**
* @testWith ["0"]
* ["012"]
* ["1"]
* ["42"]
* ["42198"]
Expand Down Expand Up @@ -136,6 +137,36 @@ public function testDigitsKO(string $digits)
);
}

/**
* @testWith ["1"]
* ["42"]
* ["42198"]
* ["999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"]
*/
public function testPositiveIntOK(string $digits)
{
$this->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"]
Expand Down