bug #29542 [Routing] fix dumping same-path routes with placeholders (nicolas-grekas)
This PR was merged into the 4.1 branch.
Discussion
----------
[Routing] fix dumping same-path routes with placeholders
| Q | A
| ------------- | ---
| Branch? | 4.1
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Only 4.1 is affected.
Commits
-------
94a143011a
[Routing] fix dumping same-path routes with placeholders
This commit is contained in:
commit
0960dfd658
@ -526,15 +526,10 @@ EOF;
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$prevRegex = $compiledRoute->getRegex();
|
$prevRegex = $compiledRoute->getRegex();
|
||||||
$combine = ' $matches = array(';
|
|
||||||
foreach ($vars as $j => $m) {
|
|
||||||
$combine .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
|
|
||||||
}
|
|
||||||
$combine = $vars ? substr_replace($combine, ");\n\n", -2) : '';
|
|
||||||
|
|
||||||
$state->switch .= <<<EOF
|
$state->switch .= <<<EOF
|
||||||
case {$state->mark}:
|
case {$state->mark}:
|
||||||
{$combine}{$this->compileRoute($route, $name, false, $hasTrailingSlash)}
|
{$this->compileRoute($route, $name, false, $hasTrailingSlash, $vars)}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
@ -621,7 +616,7 @@ EOF;
|
|||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws \LogicException
|
||||||
*/
|
*/
|
||||||
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash): string
|
private function compileRoute(Route $route, string $name, bool $checkHost, bool $hasTrailingSlash, array $vars = null): string
|
||||||
{
|
{
|
||||||
$compiledRoute = $route->compile();
|
$compiledRoute = $route->compile();
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
@ -669,6 +664,14 @@ EOF;
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($vars) {
|
||||||
|
$code .= ' $matches = array(';
|
||||||
|
foreach ($vars as $j => $m) {
|
||||||
|
$code .= sprintf('%s => $matches[%d] ?? null, ', self::export($m), 1 + $j);
|
||||||
|
}
|
||||||
|
$code = substr_replace($code, ");\n\n", -2);
|
||||||
|
}
|
||||||
|
|
||||||
if ($route->getCondition()) {
|
if ($route->getCondition()) {
|
||||||
$expression = $this->getExpressionLanguage()->compile($route->getCondition(), array('context', 'request'));
|
$expression = $this->getExpressionLanguage()->compile($route->getCondition(), array('context', 'request'));
|
||||||
|
|
||||||
|
@ -139,8 +139,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
||||||
switch ($m = (int) $matches['MARK']) {
|
switch ($m = (int) $matches['MARK']) {
|
||||||
case 115:
|
case 115:
|
||||||
$matches = array('foo' => $matches[1] ?? null);
|
|
||||||
|
|
||||||
// baz4
|
// baz4
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
goto not_baz4;
|
goto not_baz4;
|
||||||
@ -149,6 +147,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
$matches = $n;
|
$matches = $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo' => $matches[1] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
||||||
not_baz4:
|
not_baz4:
|
||||||
|
|
||||||
@ -188,13 +188,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 160:
|
case 160:
|
||||||
$matches = array('foo' => $matches[1] ?? null);
|
|
||||||
|
|
||||||
// foo1
|
// foo1
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
goto not_foo1;
|
goto not_foo1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo' => $matches[1] ?? null);
|
||||||
|
|
||||||
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
||||||
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
|
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
|
||||||
$allow += $a;
|
$allow += $a;
|
||||||
@ -206,25 +206,25 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 204:
|
case 204:
|
||||||
$matches = array('foo1' => $matches[1] ?? null);
|
|
||||||
|
|
||||||
// foo2
|
// foo2
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
goto not_foo2;
|
goto not_foo2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo1' => $matches[1] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
||||||
not_foo2:
|
not_foo2:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 279:
|
case 279:
|
||||||
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
|
||||||
|
|
||||||
// foo3
|
// foo3
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
goto not_foo3;
|
goto not_foo3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
||||||
not_foo3:
|
not_foo3:
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
||||||
switch ($m = (int) $matches['MARK']) {
|
switch ($m = (int) $matches['MARK']) {
|
||||||
case 56:
|
case 56:
|
||||||
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
|
||||||
|
|
||||||
// r1
|
// r1
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
goto not_r1;
|
goto not_r1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'r1') + $matches, array());
|
||||||
not_r1:
|
not_r1:
|
||||||
|
|
||||||
|
@ -179,8 +179,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
while (preg_match($regex, $matchedPathinfo, $matches)) {
|
||||||
switch ($m = (int) $matches['MARK']) {
|
switch ($m = (int) $matches['MARK']) {
|
||||||
case 115:
|
case 115:
|
||||||
$matches = array('foo' => $matches[1] ?? null);
|
|
||||||
|
|
||||||
// baz4
|
// baz4
|
||||||
if ('/' !== $pathinfo[-1]) {
|
if ('/' !== $pathinfo[-1]) {
|
||||||
if ('GET' === $canonicalMethod) {
|
if ('GET' === $canonicalMethod) {
|
||||||
@ -192,6 +190,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
$matches = $n;
|
$matches = $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo' => $matches[1] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'baz4') + $matches, array());
|
||||||
not_baz4:
|
not_baz4:
|
||||||
|
|
||||||
@ -231,13 +231,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 160:
|
case 160:
|
||||||
$matches = array('foo' => $matches[1] ?? null);
|
|
||||||
|
|
||||||
// foo1
|
// foo1
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
goto not_foo1;
|
goto not_foo1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo' => $matches[1] ?? null);
|
||||||
|
|
||||||
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
$ret = $this->mergeDefaults(array('_route' => 'foo1') + $matches, array());
|
||||||
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
|
if (!isset(($a = array('PUT' => 0))[$requestMethod])) {
|
||||||
$allow += $a;
|
$allow += $a;
|
||||||
@ -249,8 +249,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 204:
|
case 204:
|
||||||
$matches = array('foo1' => $matches[1] ?? null);
|
|
||||||
|
|
||||||
// foo2
|
// foo2
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
if ('GET' === $canonicalMethod) {
|
if ('GET' === $canonicalMethod) {
|
||||||
@ -259,13 +257,13 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
goto not_foo2;
|
goto not_foo2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('foo1' => $matches[1] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
|
||||||
not_foo2:
|
not_foo2:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 279:
|
case 279:
|
||||||
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
|
||||||
|
|
||||||
// foo3
|
// foo3
|
||||||
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
|
||||||
if ('GET' === $canonicalMethod) {
|
if ('GET' === $canonicalMethod) {
|
||||||
@ -274,6 +272,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
|||||||
goto not_foo3;
|
goto not_foo3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
|
||||||
|
|
||||||
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
|
||||||
not_foo3:
|
not_foo3:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user