[Routing] fix static route reordering when a previous dynamic route conflicts
This commit is contained in:
parent
f1edae020d
commit
cba3b6245a
|
@ -187,7 +187,7 @@ EOF;
|
||||||
$url = substr($url, 0, -1);
|
$url = substr($url, 0, -1);
|
||||||
}
|
}
|
||||||
foreach ($dynamicRegex as list($hostRx, $rx, $prefix)) {
|
foreach ($dynamicRegex as list($hostRx, $rx, $prefix)) {
|
||||||
if (('' === $prefix || 0 === strpos($url, $prefix)) && preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
|
if (('' === $prefix || 0 === strpos($url, $prefix)) && (preg_match($rx, $url) || preg_match($rx, $url.'/')) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
|
||||||
$dynamicRegex[] = [$hostRegex, $regex, $staticPrefix];
|
$dynamicRegex[] = [$hostRegex, $regex, $staticPrefix];
|
||||||
$dynamicRoutes->add($name, $route);
|
$dynamicRoutes->add($name, $route);
|
||||||
continue 2;
|
continue 2;
|
||||||
|
|
|
@ -929,6 +929,17 @@ class UrlMatcherTest extends TestCase
|
||||||
$this->assertEquals(['_route' => 'b', 'b' => ''], $matcher->match('/en-en/'));
|
$this->assertEquals(['_route' => 'b', 'b' => ''], $matcher->match('/en-en/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRestrictiveTrailingRequirementWithStaticRouteAfter()
|
||||||
|
{
|
||||||
|
$coll = new RouteCollection();
|
||||||
|
$coll->add('a', new Route('/hello{_}', [], ['_' => '/(?!/)']));
|
||||||
|
$coll->add('b', new Route('/hello'));
|
||||||
|
|
||||||
|
$matcher = $this->getUrlMatcher($coll);
|
||||||
|
|
||||||
|
$this->assertEquals(['_route' => 'a', '_' => '/'], $matcher->match('/hello/'));
|
||||||
|
}
|
||||||
|
|
||||||
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
|
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
|
||||||
{
|
{
|
||||||
return new UrlMatcher($routes, $context ?: new RequestContext());
|
return new UrlMatcher($routes, $context ?: new RequestContext());
|
||||||
|
|
Reference in New Issue