diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php index 5bf2b94..76126ba 100644 --- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php @@ -14,6 +14,7 @@ use Drupal\Core\Url; use Drupal\Core\Utility\LinkGenerator; use Drupal\Tests\UnitTestCase; +use Drupal\Core\DependencyInjection\ContainerBuilder; /** * @coversDefaultClass \Drupal\Core\Utility\LinkGenerator @@ -181,6 +182,40 @@ 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')); + + $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); + $url = Url::fromUserInput($path); + $url->setUrlGenerator($this->urlGenerator); + $url->setUnroutedUrlAssembler($this->urlAssembler); + + $result = $this->linkGenerator->generate('Drupal', $url); + + $this->assertLink(array( + 'attributes' => array( + 'href' => '/example?foo=%22bar%22', + ), + 'content' => 'Drupal', + ), $result, 1); + } + + /** * Tests the link method with additional attributes. * * @see \Drupal\Core\Utility\LinkGenerator::generate() diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index 0433561..ede25fe 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -125,6 +125,7 @@ public function providerTestAssembleWithLocalUri() { return [ ['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', ['fragment' => 'example', ], FALSE, '/example#example'], ['base:example', [], TRUE, '/subdir/example'], ['base:example', ['query' => ['foo' => 'bar']], TRUE, '/subdir/example?foo=bar'],