diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index d0b595f..b029266 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -140,7 +140,7 @@ public function getPathFromRoute($name, $parameters = array()) { $path = $this->processPath($path); // Remove the starting "/". - return ltrim($path, '/'); + return trim($path, '/'); } /** diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index c530ff9..621f55a 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -52,8 +52,10 @@ function setUp() { $routes = new RouteCollection(); $first_route = new Route('/test/one'); $second_route = new Route('/test/two/{narf}'); + $third_route = new Route('/test/two/'); $routes->add('test_1', $first_route); $routes->add('test_2', $second_route); + $routes->add('test_3', $third_route); // Create a route provider stub. $provider = $this->getMockBuilder('Drupal\Core\Routing\RouteProvider') @@ -62,6 +64,7 @@ function setUp() { $route_name_return_map = array( array('test_1', array(), $first_route), array('test_2', array('narf' => '5'), $second_route), + array('test_3', array(), $third_route), ); $provider->expects($this->any()) ->method('getRouteByName') @@ -69,6 +72,7 @@ function setUp() { $routes_names_return_map = array( array(array('test_1'), array(), array($first_route)), array(array('test_2'), array('narf' => '5'), array($second_route)), + array(array('test_3'), array(), array($third_route)), ); $provider->expects($this->any()) ->method('getRoutesByNames') @@ -82,6 +86,7 @@ function setUp() { array('test/one', NULL, 'hello/world'), array('test/two/5', NULL, 'goodbye/cruel/world'), array('node/123', NULL, 'node/123'), + array('test/two', NULL, 'test/two') ); $alias_manager->expects($this->any()) ->method('getPathAlias') @@ -137,6 +142,14 @@ public function testAliasGenerationWithParameters() { } /** + * Tests the url generation with trailing start and end. + */ + public function testGetPathFromRouteTrailing() { + $path = $this->generator->getPathFromRoute('test_3'); + $this->assertEquals($path, 'test/two'); + } + + /** * Confirms that absolute URLs work with generated routes. */ public function testAbsoluteURLGeneration() {