mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 21:37:29 +00:00
removed pre-1.8 autoescape tag syntax, removed true as a valid autoescape strategy
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
* 2.0.0 (201X-XX-XX)
|
* 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
|
* 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
|
* removed the ability to register a global variable after the runtime or the extensions have been initialized
|
||||||
* improved the performance of the filesystem loader
|
* improved the performance of the filesystem loader
|
||||||
|
|||||||
+11
-13
@@ -94,19 +94,17 @@ The following options are available:
|
|||||||
replace them with a ``null`` value. When set to ``true``, Twig throws an
|
replace them with a ``null`` value. When set to ``true``, Twig throws an
|
||||||
exception instead (default to ``false``).
|
exception instead (default to ``false``).
|
||||||
|
|
||||||
* ``autoescape``: If set to ``true``, HTML auto-escaping will be enabled by
|
* ``autoescape``: Sets the default auto-escaping strategy (``filename``,
|
||||||
default for all templates (default to ``true``).
|
``html``, ``js``, ``css``, ``url``, ``html_attr``, or a PHP callback that
|
||||||
|
takes the template "filename" and returns the escaping strategy to use -- the
|
||||||
As of Twig 1.8, you can set the escaping strategy to use (``html``, ``js``,
|
callback cannot be a function name to avoid collision with built-in escaping
|
||||||
``false`` to disable).
|
strategies); set it to ``false`` to disable auto-escaping. The ``filename``
|
||||||
|
escaping strategy determines the escaping strategy to use for a template
|
||||||
As of Twig 1.9, you can set the escaping strategy to use (``css``, ``url``,
|
based on the template filename extension.
|
||||||
``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
|
The ability to set the default escaping strategy was added in Twig 1.8 and
|
||||||
to avoid collision with built-in escaping strategies).
|
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.
|
||||||
As of Twig 1.17, the ``filename`` escaping strategy determines the escaping
|
|
||||||
strategy to use for a template based on the template filename extension.
|
|
||||||
|
|
||||||
* ``optimizations``: A flag that indicates which optimizations to apply
|
* ``optimizations``: A flag that indicates which optimizations to apply
|
||||||
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
|
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ class Twig_Environment
|
|||||||
*
|
*
|
||||||
* * autoescape: Whether to enable auto-escaping (default to html):
|
* * autoescape: Whether to enable auto-escaping (default to html):
|
||||||
* * false: disable auto-escaping
|
* * false: disable auto-escaping
|
||||||
* * true: equivalent to html
|
|
||||||
* * html, js: set the autoescaping to one of the supported strategies
|
* * html, js: set the autoescaping to one of the supported strategies
|
||||||
* * filename: set the autoescaping strategy based on the template filename extension
|
* * 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"
|
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
|
||||||
|
|||||||
@@ -59,11 +59,6 @@ class Twig_Extension_Escaper extends Twig_Extension
|
|||||||
*/
|
*/
|
||||||
public function setDefaultStrategy($defaultStrategy)
|
public function setDefaultStrategy($defaultStrategy)
|
||||||
{
|
{
|
||||||
// for BC
|
|
||||||
if (true === $defaultStrategy) {
|
|
||||||
$defaultStrategy = 'html';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('filename' === $defaultStrategy) {
|
if ('filename' === $defaultStrategy) {
|
||||||
$defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess');
|
$defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,21 +11,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks a section of a template to be escaped or not.
|
* 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
|
class Twig_TokenParser_AutoEscape extends Twig_TokenParser
|
||||||
{
|
{
|
||||||
@@ -46,23 +31,9 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
|
|||||||
} else {
|
} else {
|
||||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||||
if (!$expr instanceof Twig_Node_Expression_Constant) {
|
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');
|
$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);
|
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testMacrosInASandbox()
|
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 %}
|
{%- import _self as macros %}
|
||||||
|
|
||||||
{%- macro test(text) %}<p>{{ text }}</p>{% endmacro %}
|
{%- macro test(text) %}<p>{{ text }}</p>{% endmacro %}
|
||||||
|
|||||||
@@ -10,9 +10,6 @@
|
|||||||
{% autoescape false %}
|
{% autoescape false %}
|
||||||
{{ var }}<br />
|
{{ var }}<br />
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
{% autoescape true %}
|
|
||||||
{{ var }}<br />
|
|
||||||
{% endautoescape %}
|
|
||||||
{% autoescape false %}
|
{% autoescape false %}
|
||||||
{{ var }}<br />
|
{{ var }}<br />
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
@@ -22,5 +19,4 @@ return array('var' => '<br />')
|
|||||||
<br /><br />
|
<br /><br />
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<br /><br />
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
"autoescape" tag accepts an escaping strategy
|
"autoescape" tag accepts an escaping strategy
|
||||||
--TEMPLATE--
|
--TEMPLATE--
|
||||||
{% autoescape true js %}{{ var }}{% endautoescape %}
|
|
||||||
|
|
||||||
{% autoescape true html %}{{ var }}{% endautoescape %}
|
|
||||||
|
|
||||||
{% autoescape 'js' %}{{ var }}{% endautoescape %}
|
{% autoescape 'js' %}{{ var }}{% endautoescape %}
|
||||||
|
|
||||||
{% autoescape 'html' %}{{ var }}{% endautoescape %}
|
{% autoescape 'html' %}{{ var }}{% endautoescape %}
|
||||||
@@ -13,5 +9,3 @@ return array('var' => '<br />"')
|
|||||||
--EXPECT--
|
--EXPECT--
|
||||||
\x3Cbr\x20\x2F\x3E\x22
|
\x3Cbr\x20\x2F\x3E\x22
|
||||||
<br />"
|
<br />"
|
||||||
\x3Cbr\x20\x2F\x3E\x22
|
|
||||||
<br />"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user