bug #38372 [Routing] fix using !important and defaults/reqs in inline route definitions (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[Routing] fix using !important and defaults/reqs in inline route definitions
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #33224
| License | MIT
| Doc PR | -
Commits
-------
826db225b7
[Routing] fix using !important and defaults/reqs in inline route definitions
This commit is contained in:
commit
9c8a3009cf
@ -137,7 +137,7 @@ class Route implements \Serializable
|
||||
public function setPath($pattern)
|
||||
{
|
||||
if (false !== strpbrk($pattern, '?<')) {
|
||||
$pattern = preg_replace_callback('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
|
||||
$pattern = preg_replace_callback('#\{(!?\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
|
||||
if (isset($m[3][0])) {
|
||||
$this->setDefault($m[1], '?' !== $m[3] ? substr($m[3], 1) : null);
|
||||
}
|
||||
|
@ -208,6 +208,7 @@ class RouteTest extends TestCase
|
||||
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', null), new Route('/foo/{bar?}'));
|
||||
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?baz}'));
|
||||
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz<buz>'), new Route('/foo/{bar?baz<buz>}'));
|
||||
$this->assertEquals((new Route('/foo/{!bar}'))->setDefault('!bar', 'baz<buz>'), new Route('/foo/{!bar?baz<buz>}'));
|
||||
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?}', ['bar' => 'baz']));
|
||||
|
||||
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '.*'), new Route('/foo/{bar<.*>}'));
|
||||
|
Reference in New Issue
Block a user