mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 21:07:18 +00:00
Merge branch '1.x' into 2.x
* 1.x: Add a test fix typo in ApplyTokenParser PHP doc Fixes #3351
This commit is contained in:
@@ -34,12 +34,19 @@ class SandboxNode extends Node
|
||||
->write("\$this->sandbox->enableSandbox();\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->write("try {\n")
|
||||
->indent()
|
||||
->subcompile($this->getNode('body'))
|
||||
->outdent()
|
||||
->write("} finally {\n")
|
||||
->indent()
|
||||
->write("if (!\$alreadySandboxed) {\n")
|
||||
->indent()
|
||||
->write("\$this->sandbox->disableSandbox();\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Token;
|
||||
*
|
||||
* {% apply upper %}
|
||||
* This text becomes uppercase
|
||||
* {% endapplys %}
|
||||
* {% endapply %}
|
||||
*/
|
||||
final class ApplyTokenParser extends AbstractTokenParser
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Twig\Tests\Extension;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Extension\SandboxExtension;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
use Twig\Sandbox\SecurityError;
|
||||
@@ -50,6 +51,8 @@ class SandboxTest extends TestCase
|
||||
'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] }}',
|
||||
'1_syntax_error_wrapper' => '{% sandbox %}{% include "1_syntax_error" %}{% endsandbox %}',
|
||||
'1_syntax_error' => '{% syntax error }}'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -81,6 +84,18 @@ class SandboxTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testIfSandBoxIsDisabledAfterSyntaxError()
|
||||
{
|
||||
$twig = $this->getEnvironment(false, [], self::$templates);
|
||||
try {
|
||||
$twig->load('1_syntax_error_wrapper')->render(self::$params);
|
||||
} catch (SyntaxError $e) {
|
||||
/** @var SandboxExtension $sandbox */
|
||||
$sandbox = $twig->getExtension(SandboxExtension::class);
|
||||
$this->assertFalse($sandbox->isSandboxed());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSandboxUnallowedFilter()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, [], self::$templates);
|
||||
|
||||
@@ -5,6 +5,7 @@ not
|
||||
{{ not false ? 'OK' : 'KO' }}
|
||||
{{ (not false)?'OK':'KO' }}
|
||||
{{ not false?'OK':'KO' }}
|
||||
{{not true ? 'KO' : 'OK'}}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
@@ -12,3 +13,4 @@ OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
|
||||
@@ -37,9 +37,12 @@ class SandboxTest extends NodeTestCase
|
||||
if (!\$alreadySandboxed = \$this->sandbox->isSandboxed()) {
|
||||
\$this->sandbox->enableSandbox();
|
||||
}
|
||||
echo "foo";
|
||||
if (!\$alreadySandboxed) {
|
||||
\$this->sandbox->disableSandbox();
|
||||
try {
|
||||
echo "foo";
|
||||
} finally {
|
||||
if (!\$alreadySandboxed) {
|
||||
\$this->sandbox->disableSandbox();
|
||||
}
|
||||
}
|
||||
EOF
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user