Commit 6172eeca authored by Dries's avatar Dries

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

Issue #1915752 by dawehner, tim.plunkett: routes are not found when 0 is used as a placeholder value.
parent 71b4a0d0
......@@ -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 {
......
......@@ -97,7 +97,11 @@ public function getRouteCollectionForRequest(Request $request) {
$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);
......
......@@ -271,6 +271,41 @@ function testOutlinePathMatchDefaultsCollision2() {
}
}
/**
* 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.
*/
......
......@@ -57,9 +57,13 @@ public function testDefaultController() {
* 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.
......
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