mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
added the possibility to force the escaping of a string already marked as safe
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 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
|
||||
|
||||
|
||||
@@ -470,14 +470,15 @@ function twig_strtr($pattern, $replacements)
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
"escape" filter
|
||||
--TEMPLATE--
|
||||
{% set foo %}
|
||||
foo<br />
|
||||
{% endset %}
|
||||
|
||||
{{ foo|e('html') -}}
|
||||
{{ foo|e('js') }}
|
||||
{% autoescape true %}
|
||||
{{ foo }}
|
||||
{% endautoescape %}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXPECT--
|
||||
foo<br />
|
||||
foo\x3cbr \x2f\x3e\x0a
|
||||
foo<br />
|
||||
Reference in New Issue
Block a user