Permalink
Browse files

implement consistent treatment of closures; closes #1881

  • Loading branch information...
WanWizard committed Jul 3, 2015
1 parent 660ba69 commit 627441c5341e698b5dd6e8553dab3879f81794c3
Showing with 18 additions and 4 deletions.
  1. +13 −4 classes/view.php
  2. +5 −0 config/config.php
View
@@ -45,6 +45,11 @@ class View
*/
protected $auto_filter = true;
+ /**
+ * @var bool Whether to filter closures
+ */
+ protected $filter_closures = true;
+
/**
* @var array Holds a list of specific filter rules for local variables
*/
@@ -113,6 +118,8 @@ public function __construct($file = null, $data = null, $filter = null)
$this->auto_filter = is_null($filter) ? \Config::get('security.auto_filter_output', true) : $filter;
+ $this->filter_closures = \Config::get('filter_closures', true);
+
if ($file !== null)
{
$this->set_filename($file);
@@ -270,12 +277,14 @@ protected function get_data($scope = 'all')
$filter = array_key_exists($key, $rules) ? $rules[$key] : null;
$filter = is_null($filter) ? $auto_filter : $filter;
- if ($value instanceOf \Closure)
+ if ($filter)
{
- $value = $value();
+ if ($this->filter_closures and $value instanceOf \Closure)
+ {
+ $value = $value();
+ }
+ $value = \Security::clean($value, null, 'security.output_filter');
}
-
- $value = $filter ? \Security::clean($value, null, 'security.output_filter') : $value;
}
return $data;
View
@@ -222,6 +222,11 @@
*/
'auto_filter_output' => true,
+ /**
+ * Whether to filter closures as well
+ */
+ 'filter_closures' => true,
+
/**
* With output encoding switched on all objects passed will be converted to strings or
* throw exceptions unless they are instances of the classes in this array.

0 comments on commit 627441c

Please sign in to comment.