From: henrikbjorn Date: Fri, 1 Oct 2010 11:48:52 +0000 (+0200) Subject: renamed |safe to |raw to avoid unnecesarry confusion about what the tags does. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=56caee09379e5b795ba0405b721aa997f8afa876;p=web%2Fkonrad%2Ftwig.git renamed |safe to |raw to avoid unnecesarry confusion about what the tags does. Discussion can be viewed here http://groups.google.com/group/symfony-devs/browse_thread/thread/b927063310c74411. All tests pass. --- diff --git a/CHANGELOG b/CHANGELOG index 566662b..47143dc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Backward incompatibilities: * the self special variable has been renamed to _self * the odd and even filters are now tests: {{ foo|odd }} must now be written {{ foo is odd }} + * the "safe" filter has been renamed to "raw" * the implementation of template inheritance has been rewritten (blocks can now be called individually and still work with inheritance) diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index d46c1d6..35a1894 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -434,7 +434,7 @@ template to be escaped or not by using the `autoescape` tag: When automatic escaping is enabled everything is escaped by default except for values explicitly marked as safe. Those can be marked in the template by using -the `|safe` filter. +the `|raw` filter. Functions returning template data (like macros and `parent`) always return safe markup. @@ -1198,14 +1198,14 @@ might contain such characters in HTML. >**NOTE** >Internally, `escape` uses the PHP `htmlspecialchars` function. -### `safe` +### `raw` -The `safe` filter marks the value as safe which means that in an environment +The `raw` filter marks the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped. [twig] {% autoescape on } - {{ var|safe }} {# var won't be escaped #} + {{ var|raw }} {# var won't be escaped #} {% autoescape off %} ### `constant` (new in Twig 0.9.9) diff --git a/doc/03-Twig-for-Developers.markdown b/doc/03-Twig-for-Developers.markdown index 665ada6..e973f6e 100644 --- a/doc/03-Twig-for-Developers.markdown +++ b/doc/03-Twig-for-Developers.markdown @@ -299,7 +299,7 @@ registered by default. ### Escaper Extension The `escaper` extension adds automatic output escaping to Twig. It defines a -new tag, `autoescape`, and a new filter, `safe`. +new tag, `autoescape`, and a new filter, `raw`. When creating the escaper extension, you can switch on or off the global output escaping strategy: @@ -309,17 +309,17 @@ output escaping strategy: $twig->addExtension($escaper); If set to `true`, all variables in templates are escaped, except those using -the `safe` filter: +the `raw` filter: [twig] - {{ article.to_html|safe }} + {{ article.to_html|raw }} You can also change the escaping mode locally by using the `autoescape` tag: [twig] {% autoescape on %} {% var %} - {% var|safe %} {# var won't be escaped #} + {% var|raw %} {# var won't be escaped #} {% var|escape %} {# var won't be doubled-escaped #} {% endautoescape %} @@ -345,21 +345,21 @@ Twig 0.9.5 and above): [twig] {{ var|nl2br }} {# is equivalent to {{ var|escape|nl2br }} #} - * The `safe` filter can be used anywhere in the filter chain: + * The `raw` filter can be used anywhere in the filter chain: [twig] - {{ var|upper|nl2br|safe }} {# is equivalent to {{ var|safe|upper|nl2br }} #} + {{ var|upper|nl2br|raw }} {# is equivalent to {{ var|raw|upper|nl2br }} #} * Automatic escaping is applied to filter arguments, except for literals: [twig] {{ var|foo("bar") }} {# "bar" won't be escaped #} {{ var|foo(bar) }} {# bar will be escaped #} - {{ var|foo(bar|safe) }} {# bar won't be escaped #} + {{ var|foo(bar|raw) }} {# bar won't be escaped #} * Automatic escaping is not applied if one of the filters in the chain has the `is_escaper` option set to `true` (this is the case for the built-in - `escaper`, `safe`, and `urlencode` filters for instance). + `escaper`, `raw`, and `urlencode` filters for instance). ### Sandbox Extension diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index cf43ad6..5476800 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -45,7 +45,7 @@ class Twig_Extension_Escaper extends Twig_Extension public function getFilters() { return array( - 'safe' => new Twig_Filter_Function('twig_safe_filter', array('is_escaper' => true)), + 'raw' => new Twig_Filter_Function('twig_raw_filter', array('is_escaper' => true)), ); } @@ -66,7 +66,7 @@ class Twig_Extension_Escaper extends Twig_Extension } // tells the escaper node visitor that the string is safe -function twig_safe_filter($string) +function twig_raw_filter($string) { return $string; } diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test b/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test index 54cbe99..c7a5aba 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test @@ -5,7 +5,7 @@ {{ var|nl2br("
") }} {{ var|nl2br("
"|escape) }} {{ var|nl2br(sep) }} -{{ var|nl2br(sep|safe) }} +{{ var|nl2br(sep|raw) }} {% endautoescape %} --DATA-- return array('var' => "\nTwig", 'sep' => '
') diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/safe.test b/test/Twig/Tests/Fixtures/tags/raw.test similarity index 60% rename from test/Twig/Tests/Fixtures/tags/autoescape/safe.test rename to test/Twig/Tests/Fixtures/tags/raw.test index 9c45c0e..ea19b5e 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/safe.test +++ b/test/Twig/Tests/Fixtures/tags/raw.test @@ -1,8 +1,8 @@ --TEST-- -"autoescape" tag does not escape when safe is used as a filter +"autoescape" tag does not escape when raw is used as a filter --TEMPLATE-- {% autoescape on %} -{{ var|safe }} +{{ var|raw }} {% endautoescape %} --DATA-- return array('var' => '
')