removed pre-1.8 autoescape tag syntax, removed true as a valid autoescape strategy

This commit is contained in:
Fabien Potencier
2014-12-28 16:52:08 +01:00
parent 706d659deb
commit 6c3febca9e
8 changed files with 15 additions and 60 deletions
+2
View File
@@ -1,5 +1,7 @@
* 2.0.0 (201X-XX-XX)
* removed `true` as an equivalent to `html` for the auto-escaping strategy
* removed pre-1.8 autoescape tag syntax
* dropped support for PHP 5.2, 5.3, and 5.4
* removed the ability to register a global variable after the runtime or the extensions have been initialized
* improved the performance of the filesystem loader
+11 -13
View File
@@ -94,19 +94,17 @@ The following options are available:
replace them with a ``null`` value. When set to ``true``, Twig throws an
exception instead (default to ``false``).
* ``autoescape``: If set to ``true``, HTML auto-escaping will be enabled by
default for all templates (default to ``true``).
As of Twig 1.8, you can set the escaping strategy to use (``html``, ``js``,
``false`` to disable).
As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``,
``html_attr``, or a PHP callback that takes the template "filename" and must
return the escaping strategy to use -- the callback cannot be a function name
to avoid collision with built-in escaping strategies).
As of Twig 1.17, the ``filename`` escaping strategy determines the escaping
strategy to use for a template based on the template filename extension.
* ``autoescape``: Sets the default auto-escaping strategy (``filename``,
``html``, ``js``, ``css``, ``url``, ``html_attr``, or a PHP callback that
takes the template "filename" and returns the escaping strategy to use -- the
callback cannot be a function name to avoid collision with built-in escaping
strategies); set it to ``false`` to disable auto-escaping. The ``filename``
escaping strategy determines the escaping strategy to use for a template
based on the template filename extension.
The ability to set the default escaping strategy was added in Twig 1.8 and
the ``css``, ``url``, ``html_attr``, the callback strategies were added in
Twig 1.9, and the ``filename`` escaping strategy was added in Twig 1.17.
* ``optimizations``: A flag that indicates which optimizations to apply
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
-1
View File
@@ -70,7 +70,6 @@ class Twig_Environment
*
* * autoescape: Whether to enable auto-escaping (default to html):
* * false: disable auto-escaping
* * true: equivalent to html
* * html, js: set the autoescaping to one of the supported strategies
* * filename: set the autoescaping strategy based on the template filename extension
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
-5
View File
@@ -59,11 +59,6 @@ class Twig_Extension_Escaper extends Twig_Extension
*/
public function setDefaultStrategy($defaultStrategy)
{
// for BC
if (true === $defaultStrategy) {
$defaultStrategy = 'html';
}
if ('filename' === $defaultStrategy) {
$defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess');
}
+1 -30
View File
@@ -11,21 +11,6 @@
/**
* Marks a section of a template to be escaped or not.
*
* <pre>
* {% autoescape true %}
* Everything will be automatically escaped in this block
* {% endautoescape %}
*
* {% autoescape false %}
* Everything will be outputed as is in this block
* {% endautoescape %}
*
* {% autoescape true js %}
* Everything will be automatically escaped in this block
* using the js escaping strategy
* {% endautoescape %}
* </pre>
*/
class Twig_TokenParser_AutoEscape extends Twig_TokenParser
{
@@ -46,23 +31,9 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
} else {
$expr = $this->parser->getExpressionParser()->parseExpression();
if (!$expr instanceof Twig_Node_Expression_Constant) {
throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax('An escaping strategy must be a string or false.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
$value = $expr->getAttribute('value');
$compat = true === $value || false === $value;
if (true === $value) {
$value = 'html';
}
if ($compat && $stream->test(Twig_Token::NAME_TYPE)) {
if (false === $value) {
throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
$value = $stream->next()->getValue();
}
}
$stream->expect(Twig_Token::BLOCK_END_TYPE);
+1 -1
View File
@@ -163,7 +163,7 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase
public function testMacrosInASandbox()
{
$twig = $this->getEnvironment(true, array('autoescape' => true), array('index' => <<<EOF
$twig = $this->getEnvironment(true, array('autoescape' => 'html'), array('index' => <<<EOF
{%- import _self as macros %}
{%- macro test(text) %}<p>{{ text }}</p>{% endmacro %}
@@ -10,9 +10,6 @@
{% autoescape false %}
{{ var }}<br />
{% endautoescape %}
{% autoescape true %}
{{ var }}<br />
{% endautoescape %}
{% autoescape false %}
{{ var }}<br />
{% endautoescape %}
@@ -22,5 +19,4 @@ return array('var' => '<br />')
&lt;br /&gt;<br />
&lt;br /&gt;<br />
<br /><br />
&lt;br /&gt;<br />
<br /><br />
@@ -1,10 +1,6 @@
--TEST--
"autoescape" tag accepts an escaping strategy
--TEMPLATE--
{% autoescape true js %}{{ var }}{% endautoescape %}
{% autoescape true html %}{{ var }}{% endautoescape %}
{% autoescape 'js' %}{{ var }}{% endautoescape %}
{% autoescape 'html' %}{{ var }}{% endautoescape %}
@@ -13,5 +9,3 @@ return array('var' => '<br />"')
--EXPECT--
\x3Cbr\x20\x2F\x3E\x22
&lt;br /&gt;&quot;
\x3Cbr\x20\x2F\x3E\x22
&lt;br /&gt;&quot;