From b66821e86132de41944e9833bb767f2cd1ad19d0 Mon Sep 17 00:00:00 2001 From: Alexey Malihin Date: Thu, 2 Jul 2015 21:53:17 +0300 Subject: [PATCH 1/7] Update batch filter docs with arguments --- doc/filters/batch.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/filters/batch.rst b/doc/filters/batch.rst index da47eb6e6..a3966af8e 100644 --- a/doc/filters/batch.rst +++ b/doc/filters/batch.rst @@ -43,3 +43,9 @@ The above example will be rendered as: No item + +Arguments +--------- + +* ``batch size``: Count in one batch. Fractional number will be rounded up. +* ``placeholder``: Used to fill in missing items From 782301435135cdbfda8b1933d66a438ede33173e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 3 Jul 2015 08:59:01 +0200 Subject: [PATCH 2/7] fixed docs --- doc/filters/batch.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/filters/batch.rst b/doc/filters/batch.rst index a3966af8e..f8b6fa9d4 100644 --- a/doc/filters/batch.rst +++ b/doc/filters/batch.rst @@ -47,5 +47,5 @@ The above example will be rendered as: Arguments --------- -* ``batch size``: Count in one batch. Fractional number will be rounded up. -* ``placeholder``: Used to fill in missing items +* ``size``: The size of the batch; fractional numbers will be rounded up +* ``fill``: Used to fill in missing items From 8af1355e43ab824d0ea969109a7ac5902954f90d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Guerder Date: Mon, 29 Jun 2015 17:21:19 +0200 Subject: [PATCH 3/7] Example about how to rename several blocks It was unclear to me how to rename more than 1 imported block. I had to look into the source code to find that, so I add it to the documentation. --- doc/tags/use.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tags/use.rst b/doc/tags/use.rst index a2f3af090..071b1975e 100644 --- a/doc/tags/use.rst +++ b/doc/tags/use.rst @@ -74,7 +74,7 @@ is ignored. To avoid name conflicts, you can rename imported blocks: {% extends "base.html" %} - {% use "blocks.html" with sidebar as base_sidebar %} + {% use "blocks.html" with sidebar as base_sidebar, title as base_title %} {% block sidebar %}{% endblock %} {% block title %}{% endblock %} From af728947d6666f659bfdb29aae7870cf6f0b2b8a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 3 Jul 2015 09:28:44 +0200 Subject: [PATCH 4/7] fixed sandbox disabling when using the include function --- CHANGELOG | 2 +- lib/Twig/Extension/Core.php | 9 ++++++++- .../functions/include/sandbox_disabling.test | 16 ++++++++++++++++ .../sandbox_disabling_ignore_missing.test | 13 +++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/functions/include/sandbox_disabling.test create mode 100644 test/Twig/Tests/Fixtures/functions/include/sandbox_disabling_ignore_missing.test diff --git a/CHANGELOG b/CHANGELOG index 26a158864..1bb17601a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.18.3 (2015-XX-XX) - * n/a + * fixed sandbox disabling when using the include function * 1.18.2 (2015-06-06) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 82a558586..ffb077217 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -1427,10 +1427,15 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a } } + $result = null; try { - return $env->resolveTemplate($template)->render($variables); + $result = $env->resolveTemplate($template)->render($variables); } catch (Twig_Error_Loader $e) { if (!$ignoreMissing) { + if ($isSandboxed && !$alreadySandboxed) { + $sandbox->disableSandbox(); + } + throw $e; } } @@ -1438,6 +1443,8 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a if ($isSandboxed && !$alreadySandboxed) { $sandbox->disableSandbox(); } + + return $result; } /** diff --git a/test/Twig/Tests/Fixtures/functions/include/sandbox_disabling.test b/test/Twig/Tests/Fixtures/functions/include/sandbox_disabling.test new file mode 100644 index 000000000..8ffc49225 --- /dev/null +++ b/test/Twig/Tests/Fixtures/functions/include/sandbox_disabling.test @@ -0,0 +1,16 @@ +--TEST-- +"include" tag sandboxed +--TEMPLATE-- +{{ include("foo.twig", sandboxed = true) }} +{{ include("bar.twig") }} +--TEMPLATE(foo.twig)-- +foo +--TEMPLATE(bar.twig)-- +{{ foo|e }} +--DATA-- +return array('foo' => 'bar
') +--EXPECT-- +foo + + +bar<br /> diff --git a/test/Twig/Tests/Fixtures/functions/include/sandbox_disabling_ignore_missing.test b/test/Twig/Tests/Fixtures/functions/include/sandbox_disabling_ignore_missing.test new file mode 100644 index 000000000..8bf6e102d --- /dev/null +++ b/test/Twig/Tests/Fixtures/functions/include/sandbox_disabling_ignore_missing.test @@ -0,0 +1,13 @@ +--TEST-- +"include" tag sandboxed +--TEMPLATE-- +{{ include("unknown.twig", sandboxed = true, ignore_missing = true) }} +{{ include("bar.twig") }} +--TEMPLATE(bar.twig)-- +{{ foo|e }} +--DATA-- +return array('foo' => 'bar
') +--EXPECT-- + + +bar<br /> From 61eb80b08915fcbc706c05befb92f84d80e2ed2c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 3 Jul 2015 11:29:18 +0200 Subject: [PATCH 5/7] deprecated Twig_Environment::clearTemplateCache() --- CHANGELOG | 1 + doc/deprecated.rst | 6 ++++++ lib/Twig/Environment.php | 2 ++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 1bb17601a..ca1c7ff15 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.18.3 (2015-XX-XX) + * deprecated Twig_Environment::clearTemplateCache() * fixed sandbox disabling when using the include function * 1.18.2 (2015-06-06) diff --git a/doc/deprecated.rst b/doc/deprecated.rst index bde62ba5f..9c4d4d376 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -113,3 +113,9 @@ Globals * As of Twig 2.x, the ability to register a global variable after the runtime or the extensions have been initialized is not possible anymore (but changing the value of an already registered global is possible). + +Miscellaneous +------------- + +* As of Twig 1.x, ``Twig_Environment::clearTemplateCache()`` is deprecated and + will be removed in 2.0. diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 3644c2e09..8578b9d83 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -443,6 +443,8 @@ class Twig_Environment /** * Clears the internal template cache. + * + * @deprecated since 1.18.3 (to be removed in 2.0) */ public function clearTemplateCache() { From d472fcc9bdf6b08b59d3e505a8a8d0560a72972d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 3 Jul 2015 11:30:18 +0200 Subject: [PATCH 6/7] tweaked docs to avoid using an internal method in an example --- doc/internals.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/internals.rst b/doc/internals.rst index a68796b9c..ef1174dd9 100644 --- a/doc/internals.rst +++ b/doc/internals.rst @@ -124,7 +124,7 @@ using):: { // line 1 echo "Hello "; - echo twig_escape_filter($this->env, $this->getContext($context, "name"), "html", null, true); + echo twig_escape_filter($this->env, isset($context["name"]) ? $context["name"] : null), "html", null, true); } // some more code From 849adeb85ec39cb6be1b0bec887e6ddb17f16f72 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 3 Jul 2015 11:33:17 +0200 Subject: [PATCH 7/7] fixed edge case where tests would fail because of a cache issue --- lib/Twig/Test/IntegrationTestCase.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index bd7667cfa..92501569d 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -74,7 +74,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase $loader = new Twig_Loader_Array($templates); - foreach ($outputs as $match) { + foreach ($outputs as $i => $match) { $config = array_merge(array( 'cache' => false, 'strict_variables' => true, @@ -85,6 +85,11 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase $twig->addExtension($extension); } + // avoid using the same PHP class name for different cases + $p = new ReflectionProperty($twig, 'templateClassPrefix'); + $p->setAccessible(true); + $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); + try { $template = $twig->loadTemplate('index.twig'); } catch (Exception $e) { @@ -129,7 +134,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase $expected = trim($match[3], "\n "); if ($expected != $output) { - echo 'Compiled template that failed:'; + printf("Compiled templates that failed on case %d:\n", $i + 1); foreach (array_keys($templates) as $name) { echo "Template: $name\n";