diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php index 9bc00d3..a85ce5e 100644 --- a/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -130,19 +130,19 @@ public function generate($text, Url $url, $collect_cacheability_metadata = FALSE unset($variables['options']['attributes']); $url->setOptions($variables['options']); - // The result of the url generator is a plain-text URL. - // We encode it below with SafeMarkup::format because we are using it here - // in an HTML argument context. + // The result of the url generator is a plain-text URL. We format it with + //SafeMarkup::format() because we are using it an HTML argument context. if (!$collect_cacheability_metadata) { - $url = $url->toString($collect_cacheability_metadata); + $url_string = $url->toString($collect_cacheability_metadata); } else { $generated_url = $url->toString($collect_cacheability_metadata); - $url = $generated_url->getGeneratedUrl(); + $url_string = $generated_url->getGeneratedUrl(); $generated_link = GeneratedLink::createFromObject($generated_url); } + $attributes['href'] = $url_string; - $result = SafeMarkup::format('@text', ['@url' => $url, '@attributes' => $attributes, '@text' => $variables['text']]); + $result = SafeMarkup::format('@text', array('@attributes' => $attributes, '@text' => $variables['text'])); return $collect_cacheability_metadata ? $generated_link->setGeneratedLink($result) : $result; } diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php index 76126ba..9e26dd0 100644 --- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php @@ -183,24 +183,21 @@ public function testGenerateExternal() { /** * Tests the generate() method with a url containing double quotes. - * This tests that quotes are url encoded by the urlAssembler and therefore - * the final url string is not broken by being marked as safe. * * @covers ::generate */ public function testGenerateUrlWithQuotes() { $this->urlAssembler->expects($this->once()) ->method('assemble') - ->with('base:example', array('query' => array('foo' => '"bar"')) + $this->defaultOptions) - ->will($this->returnValue('/example?foo=%22bar%22')); + ->with('base:example', array('query' => array('foo' => '"bar"', 'zoo' => 'baz')) + $this->defaultOptions) + ->will($this->returnValue('/example?foo=%22bar%22&zoo=baz')); $path_validator = $this->getMock('Drupal\Core\Path\PathValidatorInterface'); $container_builder = new ContainerBuilder(); $container_builder->set('path.validator', $path_validator); \Drupal::setContainer($container_builder); - $path = '/example?foo="bar"'; - SafeMarkup::set($path); + $path = '/example?foo="bar"&zoo=baz'; $url = Url::fromUserInput($path); $url->setUrlGenerator($this->urlGenerator); $url->setUnroutedUrlAssembler($this->urlAssembler); @@ -209,7 +206,7 @@ public function testGenerateUrlWithQuotes() { $this->assertLink(array( 'attributes' => array( - 'href' => '/example?foo=%22bar%22', + 'href' => '/example?foo=%22bar%22&zoo=baz', ), 'content' => 'Drupal', ), $result, 1); diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index ede25fe..98fab07 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -126,6 +126,7 @@ public function providerTestAssembleWithLocalUri() { ['base:example', [], FALSE, '/example'], ['base:example', ['query' => ['foo' => 'bar']], FALSE, '/example?foo=bar'], ['base:example', ['query' => ['foo' => '"bar"']], FALSE, '/example?foo=%22bar%22'], + ['base:example', ['query' => ['foo' => '"bar"', 'zoo' => 'baz']], FALSE, '/example?foo=%22bar%22&zoo=baz'], ['base:example', ['fragment' => 'example', ], FALSE, '/example#example'], ['base:example', [], TRUE, '/subdir/example'], ['base:example', ['query' => ['foo' => 'bar']], TRUE, '/subdir/example?foo=bar'],