mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Merge branch '1.x' into 2.x
* 1.x: added missing else clause to avoid infinite loops fixed .. (range operator) in sandbox policy fixed version bumped version to 1.35.3-DEV prepared the 1.35.2 release
This commit is contained in:
@@ -97,7 +97,12 @@
|
||||
* improved the performance of the filesystem loader
|
||||
* removed features that were deprecated in 1.x
|
||||
|
||||
* 1.35.2 (2018-XX-XX)
|
||||
* 1.35.3 (2018-XX-XX)
|
||||
|
||||
* added missing else clause to avoid infinite loops
|
||||
* fixed .. (range operator) in sandbox policy
|
||||
|
||||
* 1.35.2 (2018-03-03)
|
||||
|
||||
* fixed a regression in the way the profiler is registered in templates
|
||||
|
||||
|
||||
@@ -314,6 +314,9 @@ class Twig_Lexer
|
||||
|
||||
$this->popState();
|
||||
++$this->cursor;
|
||||
} else {
|
||||
// unlexable
|
||||
throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,11 @@ final class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
|
||||
$this->functions[$node->getAttribute('name')] = $node;
|
||||
}
|
||||
|
||||
// the .. operator is equivalent to the range() function
|
||||
if ($node instanceof Twig_Node_Expression_Binary_Range && !isset($this->functions['range'])) {
|
||||
$this->functions['range'] = $node;
|
||||
}
|
||||
|
||||
// wrap print to check __toString() calls
|
||||
if ($node instanceof Twig_Node_Print) {
|
||||
return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag());
|
||||
|
||||
@@ -36,6 +36,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
|
||||
'1_layout' => '{% block content %}{% endblock %}',
|
||||
'1_child' => "{% extends \"1_layout\" %}\n{% block content %}\n{{ \"a\"|json_encode }}\n{% endblock %}",
|
||||
'1_include' => '{{ include("1_basic1", sandboxed=true) }}',
|
||||
'1_range_operator' => '{{ (1..2)[0] }}',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -143,6 +144,18 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testSandboxUnallowedRangeOperator()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, array(), self::$templates);
|
||||
try {
|
||||
$twig->loadTemplate('1_range_operator')->render(self::$params);
|
||||
$this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called');
|
||||
} catch (Twig_Sandbox_SecurityError $e) {
|
||||
$this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
|
||||
$this->assertEquals('range', $e->getFunctionName(), 'Exception should be raised on the "range" function');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSandboxAllowMethodFoo()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => 'foo'));
|
||||
@@ -191,6 +204,12 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals('bar', $twig->loadTemplate('1_basic7')->render(self::$params), 'Sandbox allow some functions');
|
||||
}
|
||||
|
||||
public function testSandboxAllowRangeOperator()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array(), array(), array('range'));
|
||||
$this->assertEquals('1', $twig->loadTemplate('1_range_operator')->render(self::$params), 'Sandbox allow the range operator');
|
||||
}
|
||||
|
||||
public function testSandboxAllowFunctionsCaseInsensitive()
|
||||
{
|
||||
foreach (array('getfoobar', 'getFoobar', 'getFooBar') as $name) {
|
||||
|
||||
Reference in New Issue
Block a user