fix escaping strategy that is an array but not a callable

This commit is contained in:
Tobias Schultze
2015-08-21 13:27:37 +02:00
committed by Fabien Potencier
parent 92fa52b874
commit 7f1ee9f9cb
+10 -3
View File
@@ -12,6 +12,13 @@ class Twig_Extension_Escaper extends Twig_Extension
{
protected $defaultStrategy;
/**
* Constructor.
*
* @param string|false|callable $defaultStrategy An escaping strategy
*
* @see setDefaultStrategy()
*/
public function __construct($defaultStrategy = 'html')
{
$this->setDefaultStrategy($defaultStrategy);
@@ -55,7 +62,7 @@ class Twig_Extension_Escaper extends Twig_Extension
* The strategy can be a valid PHP callback that takes the template
* "filename" as an argument and returns the strategy to use.
*
* @param mixed $defaultStrategy An escaping strategy
* @param string|false|callable $defaultStrategy An escaping strategy
*/
public function setDefaultStrategy($defaultStrategy)
{
@@ -78,13 +85,13 @@ class Twig_Extension_Escaper extends Twig_Extension
*
* @param string $filename The template "filename"
*
* @return string The default strategy to use for the template
* @return string|false The default strategy to use for the template
*/
public function getDefaultStrategy($filename)
{
// disable string callables to avoid calling a function named html or js,
// or any other upcoming escaping strategy
if (!is_string($this->defaultStrategy) && is_callable($this->defaultStrategy)) {
if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
return call_user_func($this->defaultStrategy, $filename);
}