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 />