* 1.3.0
+ * added the possibility to force the escaping of a string already marked as safe (instance of Twig_Markup)
* allowed empty templates to be used as traits
* added traits support for the "parent" function
/**
* Escapes a string.
*
- * @param Twig_Environment $env A Twig_Environment instance
- * @param string $string The value to be escaped
- * @param string $type The escaping strategy
- * @param string $charset The charset
+ * @param Twig_Environment $env A Twig_Environment instance
+ * @param string $string The value to be escaped
+ * @param string $type The escaping strategy
+ * @param string $charset The charset
+ * @param Boolean $autoescape Whether the function is called by the auto-escaping feature (true) or by the developer (false)
*/
-function twig_escape_filter(Twig_Environment $env, $string, $type = 'html', $charset = null)
+function twig_escape_filter(Twig_Environment $env, $string, $type = 'html', $charset = null, $autoescape = false)
{
- if (is_object($string) && $string instanceof Twig_Markup) {
+ if ($autoescape && is_object($string) && $string instanceof Twig_Markup) {
return $string;
}
{
$line = $node->getLine();
$name = new Twig_Node_Expression_Constant('escape', $line);
- $args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line)));
+ $args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)));
return new Twig_Node_Expression_Filter($node, $name, $args, $line);
}