diff --git a/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php index 6006f87..b8f4cd3 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php @@ -122,13 +122,15 @@ protected function getDestinationAsAbsoluteUrl($destination, $scheme_and_host) { // not yet been converted to URLs (outbound path processors and other // URL handling still needs to be performed). $destination = UrlHelper::parse($destination); - $uri = 'base:' . $destination['path']; + $path = '/' . $destination['path']; $options = [ 'query' => $destination['query'], 'fragment' => $destination['fragment'], 'absolute' => TRUE, ]; - $url = Url::fromUri($uri, $options); + // Treat this as if it's user input of a path relative to the site's + // base URL. + $url = Url::fromUserInput($path, $options); $destination = $url->toString(); } } diff --git a/core/lib/Drupal/Core/Menu/menu.api.php b/core/lib/Drupal/Core/Menu/menu.api.php index defec19..b37fa61 100644 --- a/core/lib/Drupal/Core/Menu/menu.api.php +++ b/core/lib/Drupal/Core/Menu/menu.api.php @@ -452,7 +452,7 @@ function hook_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$bread * URL. * - url: The \Drupal\Core\Url object. * - options: An associative array of additional options that will be passed - * to either \Drupal\Core\Routing\UrlGenerator::generateFromPath() or + * to either \Drupal\Core\Utility\UnroutedUrlAssembler::assemble() or * \Drupal\Core\Routing\UrlGenerator::generateFromRoute() to generate the * href attribute for this link, and also used when generating the link. * Defaults to an empty array. It may contain the following elements: @@ -469,7 +469,7 @@ function hook_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$bread * to work as an argument for the constructor of the class * Drupal\Core\Template\Attribute($options['attributes']). * - * @see \Drupal\Core\Routing\UrlGenerator::generateFromPath() + * @see \Drupal\Core\Utility\UnroutedUrlAssembler::assemble() * @see \Drupal\Core\Routing\UrlGenerator::generateFromRoute() */ function hook_link_alter(&$variables) { diff --git a/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php b/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php index b350112..59f2d0c 100644 --- a/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php +++ b/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php @@ -22,7 +22,7 @@ * The path to process, with a leading slash. * @param array $options * An array of options such as would be passed to the generator's - * generateFromPath() method. + * generateFromRoute() method. * @param \Symfony\Component\HttpFoundation\Request $request * The HttpRequest object representing the current request. * @param \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata diff --git a/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php b/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php index 6be8a5a..b4a794e 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php @@ -9,7 +9,9 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Form\FormState; +use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Url; +use Drupal\Core\Utility\UnroutedUrlAssemblerInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -29,11 +31,19 @@ class FormSubmitterTest extends UnitTestCase { protected $urlGenerator; /** + * The mocked unrouted URL assembler. + * + * @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Utility\UnroutedUrlAssemblerInterface + */ + protected $unroutedUrlAssembler; + + /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); + $this->urlGenerator = $this->getMock(UrlGeneratorInterface::class); + $this->unroutedUrlAssembler = $this->getMock(UnroutedUrlAssemblerInterface::class); } /** @@ -187,9 +197,13 @@ public function testRedirectWithResponseObject() { public function testRedirectWithoutResult() { $form_submitter = $this->getFormSubmitter(); $this->urlGenerator->expects($this->never()) - ->method('generateFromPath'); - $this->urlGenerator->expects($this->never()) ->method('generateFromRoute'); + $this->unroutedUrlAssembler->expects($this->never()) + ->method('assemble'); + $container = new ContainerBuilder(); + $container->set('url_generator', $this->urlGenerator); + $container->set('unrouted_url_assembler', $this->unroutedUrlAssembler); + \Drupal::setContainer($container); $form_state = $this->getMock('Drupal\Core\Form\FormStateInterface'); $form_state->expects($this->once()) ->method('getRedirect') diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 6607cb5..4d91218 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -349,79 +349,6 @@ public function testUrlGenerationWithHttpsRequirement() { } /** - * Tests path-based URL generation. - */ - public function testPathBasedURLGeneration() { - $base_path = '/subdir'; - $base_url = 'http://www.example.com' . $base_path; - - foreach (array('', 'index.php/') as $script_path) { - foreach (array(FALSE, TRUE) as $absolute) { - // Setup a fake request which looks like a Drupal installed under the - // subdir "subdir" on the domain www.example.com. - // To reproduce the values install Drupal like that and use a debugger. - $server = [ - 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => $this->root . '/index.php', - 'SERVER_NAME' => 'http://www.example.com', - ]; - $request = Request::create('/subdir/' . $script_path, 'GET', [], [], [], $server); - $request->headers->set('host', ['www.example.com']); - $this->requestStack->push($request); - - // Determine the expected bubbleable metadata. - $expected_cacheability = (new BubbleableMetadata()) - ->setCacheContexts($absolute ? ['url.site'] : []) - ->setCacheMaxAge(Cache::PERMANENT); - - // Get the expected start of the path string. - $base = ($absolute ? $base_url . '/' : $base_path . '/') . $script_path; - $url = $base . 'node/123'; - $result = $this->generator->generateFromPath('node/123', array('absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123#foo'; - $result = $this->generator->generateFromPath('node/123', array('fragment' => 'foo', 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('fragment' => 'foo', 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123?foo'; - $result = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123?foo=bar&bar=baz'; - $result = $this->generator->generateFromPath('node/123', array('query' => array('foo' => 'bar', 'bar' => 'baz'), 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('query' => array('foo' => 'bar', 'bar' => 'baz'), 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123?foo#bar'; - $result = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base; - $result = $this->generator->generateFromPath('', array('absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('', array('absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - } - } - } - - /** * Tests generating a relative URL with no path. * * @param array $options