Issue #2624284 by lauriii: Add toString method to Twig sandbox policy whitelist
parent
7f43e3ba9d
commit
cd4ae1b495
|
@ -57,6 +57,7 @@ class TwigSandboxPolicy implements \Twig_Sandbox_SecurityPolicyInterface {
|
||||||
'bundle',
|
'bundle',
|
||||||
'get',
|
'get',
|
||||||
'__toString',
|
'__toString',
|
||||||
|
'toString',
|
||||||
]);
|
]);
|
||||||
$this->whitelisted_methods = array_flip($whitelisted_methods);
|
$this->whitelisted_methods = array_flip($whitelisted_methods);
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,20 @@ class TwigSandboxTest extends UnitTestCase {
|
||||||
$this->assertEquals($result, 'testing', 'Sandbox policy allows get() to be called.');
|
$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 {}
|
class TestAttribute extends Attribute {}
|
||||||
|
|
Loading…
Reference in New Issue