diff --git a/core/lib/Drupal/Core/Template/TwigSandboxPolicy.php b/core/lib/Drupal/Core/Template/TwigSandboxPolicy.php
index 4adc9d6..da5a48e 100644
--- a/core/lib/Drupal/Core/Template/TwigSandboxPolicy.php
+++ b/core/lib/Drupal/Core/Template/TwigSandboxPolicy.php
@@ -58,7 +58,9 @@ public function __construct() {
'bundle',
'get',
'__toString',
+ 'toLink',
'toString',
+ 'toUrl',
]);
$this->whitelisted_methods = array_flip($whitelisted_methods);
diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php
index cf39a8b..906c0d0 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php
@@ -139,6 +139,26 @@ public function testEntitySafeMethods() {
->willReturn('testing');
$result = $this->twig->render('{{ entity.bundle }}', ['entity' => $entity]);
$this->assertEquals($result, 'testing', 'Sandbox policy allows get() to be called.');
+
+ $entity = $this->getMock('Drupal\Core\Entity\EntityInterface');
+ $entity->expects($this->atLeastOnce())
+ ->method('toLink')
+ ->withConsecutive([], [NULL, 'edit'])
+ ->willReturnOnConsecutiveCalls('This is a node', 'Home');
+ $result = $this->twig->render('{{ entity.toLink }}', ['entity' => $entity]);
+ $this->assertEquals(htmlentities('This is a node'), $result);
+ $result = $this->twig->render('{{ entity.toLink(null, "edit") }}', ['entity' => $entity]);
+ $this->assertEquals(htmlentities('Home'), $result);
+
+ $entity = $this->getMock('Drupal\Core\Entity\EntityInterface');
+ $entity->expects($this->atLeastOnce())
+ ->method('toUrl')
+ ->withConsecutive([], ['edit'])
+ ->willReturn('/node/123');
+ $result = $this->twig->render('{{ entity.toUrl }}', ['entity' => $entity]);
+ $this->assertEquals('/node/123',$result);
+ $result = $this->twig->render('{{ entity.toUrl("edit") }}', ['entity' => $entity]);
+ $this->assertEquals('/node/123',$result);
}
/**