diff --git a/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php b/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php
index 5c91e62..714f9a8 100644
--- a/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php
+++ b/core/lib/Drupal/Core/Routing/PathBasedGeneratorInterface.php
@@ -30,6 +30,19 @@
   public function generateFromPath($path = NULL, $options = array());
 
   /**
+   * Gets the path of route.
+   *
+   * @param string $name
+   *  The route name.
+   * @param array $parameters
+   *  An array of parameters as passed to Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().
+   *
+   * @return string
+   *  The internal Drupal path corresponding to the route.
+   */
+  public function getPathFromRoute($name, $parameters = array());
+
+  /**
    * Sets the $request property.
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index 04c2c17..cdb0386 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -105,10 +105,9 @@ public function setRequest(Request $request) {
   }
 
   /**
-   * Implements Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().
+   * {@inheritdoc}
    */
-  public function generate($name, $parameters = array(), $absolute = FALSE) {
-
+  public function getPathFromRoute($name, $parameters = array()) {
     if ($name instanceof SymfonyRoute) {
       $route = $name;
     }
@@ -139,6 +138,18 @@ public function generate($name, $parameters = array(), $absolute = FALSE) {
     }
 
     $path = $this->processPath($path);
+
+    // Remove any leading or trailing "/".
+    return trim($path, '/');
+  }
+
+  /**
+   * Implements Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().
+   */
+  public function generate($name, $parameters = array(), $absolute = FALSE) {
+    $path = '/' . $this->getPathFromRoute($name, $parameters);
+
+    $base_url = $this->context->getBaseUrl();
     if (!$absolute || !$host = $this->context->getHost()) {
       return $base_url . $path;
     }
diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
index 079213e..3db5808 100644
--- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
@@ -30,6 +30,11 @@
  */
 class UrlGeneratorTest extends UnitTestCase {
 
+  /**
+   * The url generator to test.
+   *
+   * @var \Drupal\Core\Routing\UrlGenerator
+   */
   protected $generator;
 
   protected $aliasManager;
@@ -47,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')
@@ -57,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')
@@ -64,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')
@@ -77,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')
@@ -105,6 +115,19 @@ function setUp() {
   public function testAliasGeneration() {
     $url = $this->generator->generate('test_1');
     $this->assertEquals('/hello/world', $url);
+
+    $path = $this->generator->getPathFromRoute('test_1');
+    $this->assertEquals('hello/world', $path);
+  }
+
+  /**
+   * Tests URL generation in a subdirectory.
+   */
+  public function testGetPathFromRouteWithSubdirectory() {
+    $this->generator->setBasePath('/test-base-path');
+
+    $path = $this->generator->getPathFromRoute('test_1');
+    $this->assertEquals('hello/world', $path);
   }
 
   /**
@@ -113,6 +136,17 @@ public function testAliasGeneration() {
   public function testAliasGenerationWithParameters() {
     $url = $this->generator->generate('test_2', array('narf' => '5'));
     $this->assertEquals('/goodbye/cruel/world', $url, 'Correct URL generated including alias and parameters.');
+
+    $path = $this->generator->getPathFromRoute('test_2', array('narf' => '5'));
+    $this->assertEquals('goodbye/cruel/world', $path);
+  }
+
+  /**
+   * Tests URL generation from route with trailing start and end slashes.
+   */
+  public function testGetPathFromRouteTrailing() {
+    $path = $this->generator->getPathFromRoute('test_3');
+    $this->assertEquals($path, 'test/two');
   }
 
   /**
