fixed partial output leak when a PHP fatal error occurs

This commit is contained in:
Fabien Potencier
2019-05-03 06:20:17 +02:00
parent d3acd0bede
commit 6196fe5b40
10 changed files with 12 additions and 11 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.40.2 (2019-XX-XX)
* fixed partial output leak when a PHP fatal error occurs
* optimized context access on PHP 7.4
* 1.40.1 (2019-04-29)
+1 -1
View File
@@ -54,7 +54,7 @@ function twig_var_dump(Environment $env, $context, array $vars = [])
return;
}
ob_start();
ob_start(function () { return ''; });
if (!$vars) {
$vars = [];
+1 -1
View File
@@ -104,7 +104,7 @@ class MacroNode extends Node
->outdent()
->write("]);\n\n")
->write("\$blocks = [];\n\n")
->write("ob_start();\n")
->write("ob_start(function () { return ''; });\n")
->write("try {\n")
->indent()
->subcompile($this->getNode('body'))
+1 -1
View File
@@ -58,7 +58,7 @@ class SetNode extends Node implements NodeCaptureInterface
} else {
if ($this->getAttribute('capture')) {
$compiler
->write("ob_start();\n")
->write("ob_start(function () { return ''; });\n")
->subcompile($this->getNode('values'))
;
}
+1 -1
View File
@@ -31,7 +31,7 @@ class SpacelessNode extends Node
{
$compiler
->addDebugInfo($this)
->write("ob_start();\n")
->write("ob_start(function () { return ''; });\n")
->subcompile($this->getNode('body'))
->write("echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));\n")
;
+3 -3
View File
@@ -253,7 +253,7 @@ abstract class Template implements \Twig_TemplateInterface
*/
public function renderParentBlock($name, array $context, array $blocks = [])
{
ob_start();
ob_start(function () { return ''; });
$this->displayParentBlock($name, $context, $blocks);
return ob_get_clean();
@@ -274,7 +274,7 @@ abstract class Template implements \Twig_TemplateInterface
*/
public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
{
ob_start();
ob_start(function () { return ''; });
$this->displayBlock($name, $context, $blocks, $useBlocks);
return ob_get_clean();
@@ -417,7 +417,7 @@ abstract class Template implements \Twig_TemplateInterface
public function render(array $context)
{
$level = ob_get_level();
ob_start();
ob_start(function () { return ''; });
try {
$this->display($context);
} catch (\Exception $e) {
+1 -1
View File
@@ -96,7 +96,7 @@ final class TemplateWrapper
{
$context = $this->env->mergeGlobals($context);
$level = ob_get_level();
ob_start();
ob_start(function () { return ''; });
try {
$this->template->displayBlock($name, $context);
} catch (\Exception $e) {
+1 -1
View File
@@ -59,7 +59,7 @@ public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
\$blocks = [];
ob_start();
ob_start(function () { return ''; });
try {
echo "foo";
} catch (\Exception \$e) {
+1 -1
View File
@@ -49,7 +49,7 @@ EOF
$node = new SetNode(true, $names, $values, 1);
$tests[] = [$node, <<<EOF
// line 1
ob_start();
ob_start(function () { return ''; });
echo "foo";
\$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset());
EOF
+1 -1
View File
@@ -32,7 +32,7 @@ class Twig_Tests_Node_SpacelessTest extends NodeTestCase
return [
[$node, <<<EOF
// line 1
ob_start();
ob_start(function () { return ''; });
echo "<div> <div> foo </div> </div>";
echo trim(preg_replace('/>\s+</', '><', ob_get_clean()));
EOF