Commit 99fc3faa authored by webchick's avatar webchick

Issue #2120505 by tstoeckler, dawehner: Remove MatcherDumper::MAX_PARTS.

parent c435b714
......@@ -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.
*
......
......@@ -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);
......
......@@ -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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment