diff --git a/CHANGELOG b/CHANGELOG
index 979ced9a4..318e1a7f6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,7 +10,8 @@
* 1.18.3 (2015-XX-XX)
- * n/a
+ * deprecated Twig_Environment::clearTemplateCache()
+ * fixed sandbox disabling when using the include function
* 1.18.2 (2015-06-06)
diff --git a/doc/filters/batch.rst b/doc/filters/batch.rst
index 8b3c8b61b..f26feba6d 100644
--- a/doc/filters/batch.rst
+++ b/doc/filters/batch.rst
@@ -40,3 +40,9 @@ The above example will be rendered as:
No item |
+
+Arguments
+---------
+
+* ``size``: The size of the batch; fractional numbers will be rounded up
+* ``fill``: Used to fill in missing items
diff --git a/doc/internals.rst b/doc/internals.rst
index bc022b087..288dcd471 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
diff --git a/doc/tags/use.rst b/doc/tags/use.rst
index 0720abce1..168cdcb27 100644
--- a/doc/tags/use.rst
+++ b/doc/tags/use.rst
@@ -71,7 +71,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 %}
diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php
index 648f13b97..0a11ec72b 100644
--- a/lib/Twig/Environment.php
+++ b/lib/Twig/Environment.php
@@ -439,6 +439,8 @@ class Twig_Environment
/**
* Clears the internal template cache.
+ *
+ * @deprecated since 1.18.3 (to be removed in 2.0)
*/
public function clearTemplateCache()
{
diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php
index 754307b33..a4f1d0e4d 100644
--- a/lib/Twig/Extension/Core.php
+++ b/lib/Twig/Extension/Core.php
@@ -1377,10 +1377,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;
}
}
@@ -1388,6 +1393,8 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
if ($isSandboxed && !$alreadySandboxed) {
$sandbox->disableSandbox();
}
+
+ return $result;
}
/**
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";
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 />