mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
tweaked sandbox generated code
This commit is contained in:
@@ -45,12 +45,13 @@ class CheckSecurityNode extends Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
|
->write("\$this->sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n")
|
||||||
->write('$tags = ')->repr(array_filter($tags))->raw(";\n")
|
->write('$tags = ')->repr(array_filter($tags))->raw(";\n")
|
||||||
->write('$filters = ')->repr(array_filter($filters))->raw(";\n")
|
->write('$filters = ')->repr(array_filter($filters))->raw(";\n")
|
||||||
->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n")
|
->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n")
|
||||||
->write("try {\n")
|
->write("try {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$this->env->getExtension('\Twig\Extension\SandboxExtension')->checkSecurity(\n")
|
->write("\$this->sandbox->checkSecurity(\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n")
|
->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n")
|
||||||
->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n")
|
->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n")
|
||||||
|
|||||||
@@ -29,16 +29,15 @@ class SandboxNode extends Node
|
|||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
->write("\$sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n")
|
->write("if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {\n")
|
||||||
->write("if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {\n")
|
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$sandbox->enableSandbox();\n")
|
->write("\$this->sandbox->enableSandbox();\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("}\n")
|
->write("}\n")
|
||||||
->subcompile($this->getNode('body'))
|
->subcompile($this->getNode('body'))
|
||||||
->write("if (!\$alreadySandboxed) {\n")
|
->write("if (!\$alreadySandboxed) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$sandbox->disableSandbox();\n")
|
->write("\$this->sandbox->disableSandbox();\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("}\n")
|
->write("}\n")
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class SandboxNodeVisitor extends AbstractNodeVisitor
|
|||||||
if ($node instanceof ModuleNode) {
|
if ($node instanceof ModuleNode) {
|
||||||
$this->inAModule = false;
|
$this->inAModule = false;
|
||||||
|
|
||||||
$node->setNode('display_start', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
|
$node->setNode('constructor_end', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ abstract class Template implements \Twig_TemplateInterface
|
|||||||
protected $env;
|
protected $env;
|
||||||
protected $blocks = [];
|
protected $blocks = [];
|
||||||
protected $traits = [];
|
protected $traits = [];
|
||||||
|
protected $sandbox;
|
||||||
|
|
||||||
public function __construct(Environment $env)
|
public function __construct(Environment $env)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,13 +32,12 @@ class Twig_Tests_Node_SandboxTest extends NodeTestCase
|
|||||||
|
|
||||||
$tests[] = [$node, <<<EOF
|
$tests[] = [$node, <<<EOF
|
||||||
// line 1
|
// line 1
|
||||||
\$sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');
|
if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {
|
||||||
if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {
|
\$this->sandbox->enableSandbox();
|
||||||
\$sandbox->enableSandbox();
|
|
||||||
}
|
}
|
||||||
echo "foo";
|
echo "foo";
|
||||||
if (!\$alreadySandboxed) {
|
if (!\$alreadySandboxed) {
|
||||||
\$sandbox->disableSandbox();
|
\$this->sandbox->disableSandbox();
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user