Issue #1915752 by dawehner, tim.plunkett: routes are not found when 0 is used as a placeholder value.

8.0.x
Dries 2013-03-22 11:28:58 -04:00
parent 71b4a0d018
commit 6172eecaa6
4 changed files with 50 additions and 5 deletions

View File

@ -5099,7 +5099,9 @@ function drupal_set_page_content($content = NULL) {
$content_block = &drupal_static(__FUNCTION__, NULL);
$main_content_display = &drupal_static('system_main_content_added', FALSE);
if (!empty($content)) {
// Filter out each empty value, though allow '0' and 0, which would be
// filtered out by empty().
if ($content !== NULL && $content !== '') {
$content_block = (is_array($content) ? $content : array('main' => array('#markup' => $content)));
}
else {

View File

@ -97,7 +97,11 @@ class RouteProvider implements RouteProviderInterface {
$path = rtrim($request->getPathInfo(), '/');
}
$parts = array_slice(array_filter(explode('/', $path)), 0, MatcherDumper::MAX_PARTS);
// 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) {
return $value !== NULL && $value !== '';
}), 0, MatcherDumper::MAX_PARTS);
$ancestors = $this->getCandidateOutlines($parts);

View File

@ -271,6 +271,41 @@ class RouteProviderTest extends UnitTestBase {
}
}
/**
* Tests a route with a 0 as value.
*/
public function testOutlinePathMatchZero() {
$connection = Database::getConnection();
$provider = new RouteProvider($connection, 'test_routes');
$this->fixtures->createTables($connection);
$collection = new RouteCollection();
$collection->add('poink', new Route('/some/path/{value}'));
$dumper = new MatcherDumper($connection, 'test_routes');
$dumper->addRoutes($collection);
$dumper->dump();
$path = '/some/path/0';
$request = Request::create($path, 'GET');
try {
$routes = $provider->getRouteCollectionForRequest($request);
// All of the matching paths have the correct pattern.
foreach ($routes as $route) {
$this->assertEqual($route->compile()->getPatternOutline(), '/some/path/%', 'Found path has correct pattern');
}
$this->assertEqual(count($routes), 1, 'The correct number of routes was found.');
}
catch (ResourceNotFoundException $e) {
$this->fail('No matchout route found with 0 as argument value');
}
}
/**
* Confirms that an exception is thrown when no matching path is found.
*/

View File

@ -57,9 +57,13 @@ class RouterTest extends WebTestBase {
* Confirms that placeholders in paths work correctly.
*/
public function testControllerPlaceholders() {
$value = $this->randomName();
$this->drupalGet('router_test/test3/' . $value);
$this->assertRaw($value, 'The correct string was returned because the route was successful.');
// Test with 0 and a random value.
$values = array("0", $this->randomName());
foreach ($values as $value) {
$this->drupalGet('router_test/test3/' . $value);
$this->assertResponse(200);
$this->assertRaw($value, 'The correct string was returned because the route was successful.');
}
// Confirm that the page wrapping is being added, so we're not getting a
// raw body returned.