diff --git a/core/lib/Drupal/Core/Routing/MatcherDumper.php b/core/lib/Drupal/Core/Routing/MatcherDumper.php index a1bfa3ec6e5917b7b628e02e680f414f029acff8..96de9186076fdef95cf3d00dc2d0fe843b4b9a90 100644 --- a/core/lib/Drupal/Core/Routing/MatcherDumper.php +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php @@ -16,11 +16,6 @@ */ class MatcherDumper implements MatcherDumperInterface { - /** - * The maximum number of path elements for a route pattern; - */ - const MAX_PARTS = 9; - /** * The database connection to which to dump route information. * diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index 9c660e887a4aa3239317430187fc240fc43ed68f..419cc75a4b83dbfcce7e8a402bb274ced740ae51 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -181,7 +181,7 @@ public function getRoutesByNames($names, $parameters = array()) { public function getCandidateOutlines(array $parts) { $number_parts = count($parts); $ancestors = array(); - $length = $number_parts - 1; + $length = $number_parts - 1; $end = (1 << $number_parts) - 1; // The highest possible mask is a 1 bit for every part of the path. We will @@ -240,9 +240,9 @@ public function getRoutesByPattern($pattern) { protected function getRoutesByPath($path) { // Filter out each empty value, though allow '0' and 0, which would be // filtered out by empty(). - $parts = array_slice(array_filter(explode('/', $path), function($value) { + $parts = array_values(array_filter(explode('/', $path), function($value) { return $value !== NULL && $value !== ''; - }), 0, MatcherDumper::MAX_PARTS); + })); $ancestors = $this->getCandidateOutlines($parts); diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/RouteProviderTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/RouteProviderTest.php index 1eafdf6c90a77d3d0a29e1a449f59d8171fce309..d9c5184aba9de65298626d30be744a725ccaa770 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/RouteProviderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/RouteProviderTest.php @@ -397,4 +397,26 @@ protected function testRouteByName() { $this->assertEqual($routes['route_d']->getPath(), '/path/three'); } + /** + * Ensures that the routing system is capable of extreme long patterns. + */ + public function testGetRoutesByPatternWithLongPatterns() { + $connection = Database::getConnection(); + $provider = new RouteProvider($connection, 'test_routes'); + + $this->fixtures->createTables($connection); + + $dumper = new MatcherDumper($connection, 'test_routes'); + $collection = new RouteCollection(); + $collection->add('long_pattern', new Route('/test/{v1}/test2/{v2}/test3/{v3}/{v4}/{v5}/{v6}/test4')); + $dumper->addRoutes($collection); + $dumper->dump(); + + $result = $provider->getRoutesByPattern('/test/1/test2/2/test3/3/4/5/6/test4'); + $this->assertEqual($result->count(), 1); + // We can't compare the values of the routes directly, nor use + // spl_object_hash() because they are separate instances. + $this->assertEqual(serialize($result->get('long_pattern')), serialize($collection->get('long_pattern')), 'The right route was found.'); + } + }