mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 18:36:53 +00:00
improved the performance of the sandbox
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.38.0 (2019-XX-XX)
|
||||
|
||||
* improved the performance of the sandbox
|
||||
* added a spaceless filter
|
||||
* added max value to the "random" function
|
||||
* made namespace classes the default classes (PSR-0 ones are aliases now)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace Twig\Node;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\FilterExpression;
|
||||
|
||||
/**
|
||||
@@ -29,10 +30,21 @@ class SandboxedPrintNode extends PrintNode
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('echo $this->env->getExtension(\'\Twig\Extension\SandboxExtension\')->ensureToStringAllowed(')
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(");\n")
|
||||
->write('echo ')
|
||||
;
|
||||
$expr = $this->getNode('expr');
|
||||
if ($expr instanceof ConstantExpression) {
|
||||
$compiler
|
||||
->subcompile($expr)
|
||||
->raw(";\n")
|
||||
;
|
||||
} else {
|
||||
$compiler
|
||||
->write('$this->env->getExtension(\'\Twig\Extension\SandboxExtension\')->ensureToStringAllowed(')
|
||||
->subcompile($expr)
|
||||
->raw(");\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\GetAttrExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Node\SandboxedPrintNode;
|
||||
use Twig\Template;
|
||||
use Twig\Test\NodeTestCase;
|
||||
|
||||
class Twig_Tests_Node_SandboxedPrintTest extends NodeTestCase
|
||||
@@ -24,11 +28,15 @@ class Twig_Tests_Node_SandboxedPrintTest extends NodeTestCase
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$tests = [];
|
||||
|
||||
$tests[] = [new SandboxedPrintNode(new ConstantExpression('foo', 1), 1), <<<EOF
|
||||
// line 1
|
||||
echo \$this->env->getExtension('\Twig\Extension\SandboxExtension')->ensureToStringAllowed("foo");
|
||||
echo "foo";
|
||||
EOF
|
||||
];
|
||||
|
||||
$tests[] = [new SandboxedPrintNode(new NameExpression('foo', 1), 1), <<<EOF
|
||||
// line 1
|
||||
echo \$this->env->getExtension('\Twig\Extension\SandboxExtension')->ensureToStringAllowed({$this->getVariableGetter('foo', false)});
|
||||
EOF
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user