Commit cd4ae1b4 authored by alexpott's avatar alexpott

Issue #2624284 by lauriii: Add toString method to Twig sandbox policy whitelist

parent 7f43e3ba
......@@ -57,6 +57,7 @@ public function __construct() {
'bundle',
'get',
'__toString',
'toString',
]);
$this->whitelisted_methods = array_flip($whitelisted_methods);
......
......@@ -140,6 +140,20 @@ public function testEntitySafeMethods() {
$this->assertEquals($result, 'testing', 'Sandbox policy allows get() to be called.');
}
/**
* Tests that safe methods inside Url objects can be called.
*/
public function testUrlSafeMethods() {
$url = $this->getMockBuilder('Drupal\Core\Url')
->disableOriginalConstructor()
->getMock();
$url->expects($this->once())
->method('toString')
->willReturn('http://kittens.cat/are/cute');
$result = $this->twig->render('{{ url.toString }}', ['url' => $url]);
$this->assertEquals($result, 'http://kittens.cat/are/cute', 'Sandbox policy allows toString() to be called.');
}
}
class TestAttribute extends Attribute {}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment