Skip to content

Commit

Permalink
bug twigphp#1382 Added isSandbox check around the __toString check in…
Browse files Browse the repository at this point in the history
… Sandbox extension (Scott Smith, smitherz82)

This PR was merged into the 1.15-dev branch.

Discussion
----------

Added isSandbox check around the __toString check in Sandbox extension

The `__toString` policy check currently still happens when the sandbox is disabled

Commits
-------

3ce4202 Added test for sandbox __toString when not enabled
8dfa432 Added isSandbox check around the __toString check
  • Loading branch information
fabpot committed May 25, 2014
2 parents e6156e2 + 3ce4202 commit 02b8062
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Twig/Extension/Sandbox.php
Expand Up @@ -93,7 +93,7 @@ public function checkPropertyAllowed($obj, $method)

public function ensureToStringAllowed($obj)
{
if (is_object($obj)) {
if ($this->isSandboxed() && is_object($obj)) {
$this->policy->checkMethodAllowed($obj, '__toString');
}

Expand Down
5 changes: 5 additions & 0 deletions test/Twig/Tests/Extension/SandboxTest.php
Expand Up @@ -111,6 +111,11 @@ public function testSandboxGloballySet()
$this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allow some methods');
$this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once');

$twig = $this->getEnvironment(false, array(), self::$templates);
FooObject::reset();
$this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled');
$this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once');

$twig = $this->getEnvironment(true, array(), self::$templates, array(), array('upper'));
$this->assertEquals('FABIEN', $twig->loadTemplate('1_basic2')->render(self::$params), 'Sandbox allow some filters');

Expand Down

0 comments on commit 02b8062

Please sign in to comment.