diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index f1f8a57..e1e984e 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -155,7 +155,8 @@ public function getPathFromRoute($name, $parameters = array()) { * The route name or other identifying string from ::getRouteDebugMessage(). * * @return string - * The url path, without any base path, including possible query string. + * The url path, without any base path, without the query string, not URL + * encoded. * * @throws MissingMandatoryParametersException * When some parameters are missing that are mandatory for the route. @@ -230,7 +231,8 @@ protected function doGenerate(array $variables, array $defaults, array $tokens, * $parameters merged in. * * @return string - * The url path corresponding to the route, without the base path. + * The URL path corresponding to the route, without the base path, not URL + * encoded. */ protected function getInternalPathFromRoute($name, SymfonyRoute $route, $parameters = array(), &$query_params = array()) { // The Route has a cache of its own and is not recompiled as long as it does @@ -253,9 +255,11 @@ public function generate($name, $parameters = array(), $referenceType = self::AB */ public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE) { $options += array('prefix' => ''); - if (!isset($options['query']) || !is_array($options['query'])) { - $options['query'] = array(); + // Provide a BC layer for code that passed a string in there. + if (is_string($options['query'])) { + parse_str($options['query'], $options['query']); } + $route = $this->getRoute($name); $generated_url = $collect_bubbleable_metadata ? new GeneratedUrl() : NULL; @@ -285,7 +289,8 @@ public function generateFromRoute($name, $parameters = array(), $options = array if ($options['path_processing']) { $path = $this->processPath($path, $options, $generated_url); } - // The contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request) + // The contexts base URL is already encoded + // (see Symfony\Component\HttpFoundation\Request). $path = str_replace($this->decodedChars[0], $this->decodedChars[1], rawurlencode($path)); // Drupal paths rarely include dots, so skip this processing if possible. @@ -304,14 +309,14 @@ public function generateFromRoute($name, $parameters = array(), $options = array } } - $query = $options['query'] ? '?' . UrlHelper::buildQuery($options['query']) : ''; - if (!empty($options['prefix'])) { $path = ltrim($path, '/'); $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix']; $path = '/' . str_replace('%2F', '/', rawurlencode($prefix)) . $path; } + $query = $options['query'] ? '?' . UrlHelper::buildQuery($options['query']) : ''; + // The base_url might be rewritten from the language rewrite in domain mode. if (isset($options['base_url'])) { $base_url = $options['base_url']; diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index b0c1ca3..6f7d2f8 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -505,7 +505,7 @@ public function providerTestNoPath() { } /** - * @covers \Drupal\Core\Routing\UrlGenerator::generateFromRoute + * @covers ::generateFromRoute * * Note: We use absolute covers to let * \Drupal\Tests\Core\Render\MetadataBubblingUrlGeneratorTest work. @@ -514,7 +514,7 @@ public function testGenerateWithPathProcessorChangingQueryParameter() { $path_processor = $this->getMock(OutboundPathProcessorInterface::CLASS); $path_processor->expects($this->atLeastOnce()) ->method('processOutbound') - ->willReturnCallback(function ($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) { + ->willReturnCallback(function ($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) { $options['query'] = ['zoo' => 5]; return $path; });