bug #1725 fixed sandbox disabling when using the include function (fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

fixed sandbox disabling when using the include function

closes #1668

Commits
-------

af72894 fixed sandbox disabling when using the include function
This commit is contained in:
Fabien Potencier
2015-07-03 11:20:29 +02:00
4 changed files with 38 additions and 2 deletions
+1 -1
View File
@@ -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)
+8 -1
View File
@@ -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;
}
/**
@@ -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<br />')
--EXPECT--
foo
bar&lt;br /&gt;
@@ -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<br />')
--EXPECT--
bar&lt;br /&gt;