From: Fabien Potencier Date: Wed, 29 Dec 2010 12:11:03 +0000 (+0100) Subject: changed autoescape first argument from on/off to the standard true/false X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=dee2656c9d96bd3db14b0c57bae955d0fceeba4c;p=web%2Fkonrad%2Ftwig.git changed autoescape first argument from on/off to the standard true/false --- diff --git a/CHANGELOG b/CHANGELOG index a397469..6737cd0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ Backward incompatibilities: * the constant filter has been converted to a function: {{ some_date|date('DATE_W3C'|constant) }} -> {{ some_date|date(constant('DATE_W3C')) }} * the cycle filter has been converted to a function: {{ ['odd', 'even']|cycle(i) }} -> {{ cycle(['odd', 'even'], i) }} * the for tag does not support "joined by" anymore + * the autoescape first argument is now true/false (instead of on/off) Changes: diff --git a/doc/api.rst b/doc/api.rst index 3abc46c..4feec59 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -341,7 +341,7 @@ You can also change the escaping mode locally by using the ``autoescape`` tag: .. code-block:: jinja - {% autoescape on %} + {% autoescape true %} {% var %} {% var|raw %} {# var won't be escaped #} {% var|escape %} {# var won't be doubled-escaped #} @@ -401,7 +401,7 @@ Twig 0.9.9 and above): .. code-block:: jinja - {% autoescape js on %} + {% autoescape true js %} {{ var|escape('html') }} {# will be escaped for html and javascript #} {{ var }} {# will be escaped for javascript #} {{ var|escape('js') }} {# won't be double-escaped #} diff --git a/doc/templates.rst b/doc/templates.rst index af173b4..5a4457b 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -427,15 +427,15 @@ template to be escaped or not by using the ``autoescape`` tag: .. code-block:: jinja - {% autoescape on %} + {% autoescape true %} Everything will be automatically escaped in this block {% endautoescape %} - {% autoescape off %} + {% autoescape false %} Everything will be outputed as is in this block {% endautoescape %} - {% autoescape on js %} + {% autoescape true js %} Everything will be automatically escaped in this block using the js escaping strategy {% endautoescape %} @@ -1262,9 +1262,9 @@ the last filter applied to it. .. code-block:: jinja - {% autoescape on } + {% autoescape true } {{ var|raw }} {# var won't be escaped #} - {% autoescape off %} + {% endautoescape %} ``merge`` (new in Twig 0.9.10) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index 43bccb0..5146a95 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -21,14 +21,14 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser { $lineno = $token->getLine(); $value = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); - if (!in_array($value, array('on', 'off'))) { - throw new Twig_Error_Syntax("Autoescape value must be 'on' or 'off'", $lineno); + if (!in_array($value, array('true', 'false'))) { + throw new Twig_Error_Syntax("Autoescape value must be 'true' or 'false'", $lineno); } - $value = 'on' === $value ? 'html' : false; + $value = 'true' === $value ? 'html' : false; if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) { if (false === $value) { - throw new Twig_Error_Syntax(sprintf('Unexpected escaping strategy as you set autoescaping to off.', $lineno), -1); + throw new Twig_Error_Syntax(sprintf('Unexpected escaping strategy as you set autoescaping to false.', $lineno), -1); } $value = $this->parser->getStream()->next()->getValue(); diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/basic.test b/test/Twig/Tests/Fixtures/tags/autoescape/basic.test index 6f6c1b9..62d8c3c 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/basic.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/basic.test @@ -1,16 +1,16 @@ --TEST-- "autoescape" tag applies escaping on its children --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} {{ var }}
{% endautoescape %} -{% autoescape off %} +{% autoescape false %} {{ var }}
{% endautoescape %} -{% autoescape on %} +{% autoescape true %} {{ var }}
{% endautoescape %} -{% autoescape off %} +{% autoescape false %} {{ var }}
{% endautoescape %} --DATA-- diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test b/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test index 8e05761..b48f73e 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/blocks.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag applies escaping on embedded blocks --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} {% block foo %} {{ var }} {% endblock %} diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test b/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test index fc7aa8c..fd62a84 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/double_escaping.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag does not double-escape --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} {{ var|escape }} {% endautoescape %} --DATA-- diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/functions.test b/test/Twig/Tests/Fixtures/tags/autoescape/functions.test index ce62744..9a229d0 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/functions.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/functions.test @@ -2,8 +2,8 @@ "autoescape" tag applies escaping after calling functions --TEMPLATE-- -autoescape off -{% autoescape off %} +autoescape false +{% autoescape false %} safe_br {{ safe_br() }} @@ -13,8 +13,8 @@ unsafe_br {% endautoescape %} -autoescape on -{% autoescape on %} +autoescape true +{% autoescape true %} safe_br {{ safe_br() }} @@ -36,8 +36,8 @@ unsafe_br()|escape {% endautoescape %} -autoescape on js -{% autoescape on js %} +autoescape true js +{% autoescape true js %} safe_br {{ safe_br() }} @@ -47,7 +47,7 @@ safe_br return array() --EXPECT-- -autoescape off +autoescape false safe_br
@@ -56,7 +56,7 @@ unsafe_br
-autoescape on +autoescape true safe_br
@@ -77,7 +77,7 @@ unsafe_br()|escape <br /> -autoescape on js +autoescape true js safe_br \x3cbr \x2f\x3e diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/literal.test b/test/Twig/Tests/Fixtures/tags/autoescape/literal.test index eb0a987..4c92d08 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/literal.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/literal.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag does not apply escaping on literals --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} 1. Simple literal {{ "
" }} diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/nested.test b/test/Twig/Tests/Fixtures/tags/autoescape/nested.test index 49f4da9..c911211 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/nested.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/nested.test @@ -2,11 +2,11 @@ "autoescape" tags can be nested at will --TEMPLATE-- {{ var }} -{% autoescape on %} +{% autoescape true %} {{ var }} - {% autoescape off %} + {% autoescape false %} {{ var }} - {% autoescape on %} + {% autoescape true %} {{ var }} {% endautoescape %} {{ var }} diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/objects.test b/test/Twig/Tests/Fixtures/tags/autoescape/objects.test index 12964a6..f6c03ed 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/objects.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/objects.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag applies escaping to object method calls --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} {{ user.name }} {{ user.name|lower }} {{ user }} diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test b/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test index a2c9e40..9ea4fd4 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test @@ -1,9 +1,9 @@ --TEST-- "autoescape" tag accepts an escaping strategy --TEMPLATE-- -{% autoescape on js %}{{ var }}{% endautoescape %} +{% autoescape true js %}{{ var }}{% endautoescape %} -{% autoescape on html %}{{ var }}{% endautoescape %} +{% autoescape true html %}{{ var }}{% endautoescape %} --DATA-- return array('var' => '
"') --EXPECT-- diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/type.test b/test/Twig/Tests/Fixtures/tags/autoescape/type.test index de3f6c3..17cec13 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/type.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/type.test @@ -2,39 +2,39 @@ escape types --TEMPLATE-- -1. autoescape on |escape('js') +1. autoescape true |escape('js') -{% autoescape on %} +{% autoescape true %} {% endautoescape %} -2. autoescape on html |escape('js') +2. autoescape true html |escape('js') -{% autoescape on html %} +{% autoescape true html %} {% endautoescape %} -3. autoescape on js |escape('js') +3. autoescape true js |escape('js') -{% autoescape on js %} +{% autoescape true js %} {% endautoescape %} 4. no escape -{% autoescape off %} +{% autoescape false %} {% endautoescape %} 5. |escape('js')|escape('html') -{% autoescape off %} +{% autoescape false %} {% endautoescape %} -6. autoescape on html |escape('js')|escape('html') +6. autoescape true html |escape('js')|escape('html') -{% autoescape on html %} +{% autoescape true html %} {% endautoescape %} @@ -42,15 +42,15 @@ escape types return array('msg' => "<>\n'\"") --EXPECT-- -1. autoescape on |escape('js') +1. autoescape true |escape('js') -2. autoescape on html |escape('js') +2. autoescape true html |escape('js') -3. autoescape on js |escape('js') +3. autoescape true js |escape('js') @@ -63,7 +63,7 @@ return array('msg' => "<>\n'\"") -6. autoescape on html |escape('js')|escape('html') +6. autoescape true html |escape('js')|escape('html') diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test b/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test index 53892b1..d795b82 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/with_filters.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag applies escaping after calling filters --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} (escape_and_nl2br is an escaper filter) 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 9cf12a1..0ff1ad3 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/with_filters_arguments.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag do not applies escaping on filter arguments --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} {{ var|nl2br("
") }} {{ var|nl2br("
"|escape) }} {{ var|nl2br(sep) }} diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test b/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test index a60f7c9..44d42e7 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/with_pre_escape_filters.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag applies escaping after calling filters, and before calling pre_escape filters --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} (nl2br is pre_escaped for "html" and declared safe for "html") diff --git a/test/Twig/Tests/Fixtures/tags/raw.test b/test/Twig/Tests/Fixtures/tags/raw.test index ea19b5e..86e55fd 100644 --- a/test/Twig/Tests/Fixtures/tags/raw.test +++ b/test/Twig/Tests/Fixtures/tags/raw.test @@ -1,7 +1,7 @@ --TEST-- "autoescape" tag does not escape when raw is used as a filter --TEMPLATE-- -{% autoescape on %} +{% autoescape true %} {{ var|raw }} {% endautoescape %} --DATA--