mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
Merge branch '2.x' into 3.x
* 2.x: Don't clear PHP buffer when an error occurs with debug=true Remove duplicate phpdoc
This commit is contained in:
@@ -274,7 +274,7 @@
|
||||
|
||||
* 1.42.2 (2019-XX-XX)
|
||||
|
||||
* n/a
|
||||
* Display partial output (PHP buffer) when an error occurs in debug mode
|
||||
|
||||
* 1.42.1 (2019-06-04)
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ function twig_var_dump(Environment $env, $context, ...$vars)
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start(function () { return ''; });
|
||||
ob_start();
|
||||
|
||||
if (!$vars) {
|
||||
$vars = [];
|
||||
|
||||
@@ -88,7 +88,13 @@ class MacroNode extends Node
|
||||
->outdent()
|
||||
->write("]);\n\n")
|
||||
->write("\$blocks = [];\n\n")
|
||||
->write("ob_start(function () { return ''; });\n")
|
||||
;
|
||||
if ($compiler->getEnvironment()->isDebug()) {
|
||||
$compiler->write("ob_start();\n");
|
||||
} else {
|
||||
$compiler->write("ob_start(function () { return ''; });\n");
|
||||
}
|
||||
$compiler
|
||||
->write("try {\n")
|
||||
->indent()
|
||||
->subcompile($this->getNode('body'))
|
||||
|
||||
@@ -57,8 +57,12 @@ class SetNode extends Node implements NodeCaptureInterface
|
||||
$compiler->raw(')');
|
||||
} else {
|
||||
if ($this->getAttribute('capture')) {
|
||||
if ($compiler->getEnvironment()->isDebug()) {
|
||||
$compiler->write("ob_start();\n");
|
||||
} else {
|
||||
$compiler->write("ob_start(function () { return ''; });\n");
|
||||
}
|
||||
$compiler
|
||||
->write("ob_start(function () { return ''; });\n")
|
||||
->subcompile($this->getNode('values'))
|
||||
;
|
||||
}
|
||||
|
||||
+15
-3
@@ -212,7 +212,11 @@ abstract class Template
|
||||
*/
|
||||
public function renderParentBlock($name, array $context, array $blocks = [])
|
||||
{
|
||||
ob_start(function () { return ''; });
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
$this->displayParentBlock($name, $context, $blocks);
|
||||
|
||||
return ob_get_clean();
|
||||
@@ -233,7 +237,11 @@ abstract class Template
|
||||
*/
|
||||
public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
|
||||
{
|
||||
ob_start(function () { return ''; });
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
$this->displayBlock($name, $context, $blocks, $useBlocks);
|
||||
|
||||
return ob_get_clean();
|
||||
@@ -364,7 +372,11 @@ abstract class Template
|
||||
public function render(array $context)
|
||||
{
|
||||
$level = ob_get_level();
|
||||
ob_start(function () { return ''; });
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
try {
|
||||
$this->display($context);
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
@@ -64,7 +64,11 @@ final class TemplateWrapper
|
||||
{
|
||||
$context = $this->env->mergeGlobals($context);
|
||||
$level = ob_get_level();
|
||||
ob_start(function () { return ''; });
|
||||
if ($this->env->isDebug()) {
|
||||
ob_start();
|
||||
} else {
|
||||
ob_start(function () { return ''; });
|
||||
}
|
||||
try {
|
||||
$this->template->displayBlock($name, $context);
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
@@ -200,6 +200,20 @@ EOHTML
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testTwigLeakOutputInDebugMode()
|
||||
{
|
||||
$output = exec(sprintf('%s %s debug', \PHP_BINARY, __DIR__.'/Fixtures/errors/leak-output.php'));
|
||||
|
||||
$this->assertSame('Hello OOPS', $output);
|
||||
}
|
||||
|
||||
public function testDoesNotTwigLeakOutput()
|
||||
{
|
||||
$output = exec(sprintf('%s %s', \PHP_BINARY, __DIR__.'/Fixtures/errors/leak-output.php'));
|
||||
|
||||
$this->assertSame('', $output);
|
||||
}
|
||||
}
|
||||
|
||||
class Twig_Tests_ErrorTest_Foo
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../../../../../vendor/autoload.php';
|
||||
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class BrokenExtension extends AbstractExtension
|
||||
{
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('broken', [$this, 'broken']),
|
||||
];
|
||||
}
|
||||
|
||||
public function broken()
|
||||
{
|
||||
die('OOPS');
|
||||
}
|
||||
}
|
||||
|
||||
$loader = new ArrayLoader([
|
||||
'index.html.twig' => 'Hello {{ "world"|broken }}',
|
||||
]);
|
||||
$twig = new Environment($loader, ['debug' => isset($argv[1])]);
|
||||
$twig->addExtension(new BrokenExtension());
|
||||
|
||||
echo $twig->render('index.html.twig');
|
||||
Reference in New Issue
Block a user