diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php index 256ed4db28..51cb046b33 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php @@ -187,7 +187,7 @@ EOF; $url = substr($url, 0, -1); } 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]; $dynamicRoutes->add($name, $route); continue 2; diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index 899e66b981..c6846ae8b5 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -929,6 +929,17 @@ class UrlMatcherTest extends TestCase $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) { return new UrlMatcher($routes, $context ?: new RequestContext());