What is the riht way to escape XSS in custom Twig function?
Consider this :
class TwigExtension extends \Twig_Extension
{
public function getName()
{
return 'html_helpers';
}
public function getFunctions()
{
$options = array(
'is_safe' => array('html')
);
return array(
new \Twig_SimpleFunction('greating', array($this, 'greating'),$options)
);
}
public function greating($name)
{
return "Salut ".$name;
}
}
And the call in the template : {{ greating("<script>alert('Sébastien')</script>") }}
It will display the JS alert. How can I avoid this?