Remove deprecated code

This commit is contained in:
Fabien Potencier
2024-09-10 22:45:10 +02:00
parent 9b9196c9d6
commit eb2a77d7d2
9 changed files with 0 additions and 195 deletions
-1
View File
@@ -19,7 +19,6 @@ Tags
import
include
macro
sandbox
set
types
use
-35
View File
@@ -1,35 +0,0 @@
``sandbox``
===========
.. warning::
The ``sandbox`` tag is deprecated as of Twig 3.15.
Use the ``sandboxed`` option of the ``include`` function instead.
The ``sandbox`` tag can be used to enable the sandboxing mode for an included
template, when sandboxing is not enabled globally for the Twig environment:
.. code-block:: twig
{% sandbox %}
{% include 'user.html' %}
{% endsandbox %}
.. warning::
The ``sandbox`` tag is only available when the sandbox extension is
enabled (see the :doc:`Twig for Developers<../api>` chapter).
.. note::
The ``sandbox`` tag can only be used to sandbox an include tag and it
cannot be used to sandbox a section of a template. The following example
won't work:
.. code-block:: twig
{% sandbox %}
{% for i in 1..2 %}
{{ i }}
{% endfor %}
{% endsandbox %}
-6
View File
@@ -17,7 +17,6 @@ use Twig\Sandbox\SecurityNotAllowedPropertyError;
use Twig\Sandbox\SecurityPolicyInterface;
use Twig\Sandbox\SourcePolicyInterface;
use Twig\Source;
use Twig\TokenParser\SandboxTokenParser;
final class SandboxExtension extends AbstractExtension
{
@@ -33,11 +32,6 @@ final class SandboxExtension extends AbstractExtension
$this->sourcePolicy = $sourcePolicy;
}
public function getTokenParsers(): array
{
return [new SandboxTokenParser()];
}
public function getNodeVisitors(): array
{
return [new SandboxNodeVisitor()];
-68
View File
@@ -1,68 +0,0 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\TokenParser;
use Twig\Error\SyntaxError;
use Twig\Node\IncludeNode;
use Twig\Node\Node;
use Twig\Node\SandboxNode;
use Twig\Node\TextNode;
use Twig\Token;
/**
* Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
*
* {% sandbox %}
* {% include 'user.html' %}
* {% endsandbox %}
*
* @see https://twig.symfony.com/doc/api.html#sandbox-extension for details
*
* @internal
*/
final class SandboxTokenParser extends AbstractTokenParser
{
public function parse(Token $token): Node
{
$stream = $this->parser->getStream();
trigger_deprecation('twig/twig', '3.15', \sprintf('The "sandbox" tag is deprecated in "%s" at line %d.', $stream->getSourceContext()->getName(), $token->getLine()));
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse($this->decideBlockEnd(...), true);
$stream->expect(Token::BLOCK_END_TYPE);
// in a sandbox tag, only include tags are allowed
if (!$body instanceof IncludeNode) {
foreach ($body as $node) {
if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) {
continue;
}
if (!$node instanceof IncludeNode) {
throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
}
}
}
return new SandboxNode($body, $token->getLine());
}
public function decideBlockEnd(Token $token): bool
{
return $token->test('endsandbox');
}
public function getTag(): string
{
return 'sandbox';
}
}
-16
View File
@@ -58,7 +58,6 @@ class SandboxTest extends TestCase
'1_basic2_include_template_from_string_sandboxed' => '{{ include(template_from_string("{{ name|upper }}"), sandboxed=true) }}',
'1_basic2_include_template_from_string' => '{{ include(template_from_string("{{ name|upper }}")) }}',
'1_range_operator' => '{{ (1..2)[0] }}',
'1_syntax_error_wrapper_legacy' => '{% sandbox %}{% include "1_syntax_error" %}{% endsandbox %}',
'1_syntax_error_wrapper' => '{{ include("1_syntax_error", sandboxed: true) }}',
'1_syntax_error' => '{% syntax error }}',
'1_childobj_parentmethod' => '{{ child_obj.ParentMethod() }}',
@@ -128,21 +127,6 @@ class SandboxTest extends TestCase
}
}
/**
* @group legacy
*/
public function testIfSandBoxIsDisabledAfterSyntaxErrorLegacy()
{
$twig = $this->getEnvironment(false, [], self::$templates);
try {
$twig->load('1_syntax_error_wrapper_legacy')->render(self::$params);
} catch (SyntaxError $e) {
/** @var SandboxExtension $sandbox */
$sandbox = $twig->getExtension(SandboxExtension::class);
$this->assertFalse($sandbox->isSandboxed());
}
}
public function testIfSandBoxIsDisabledAfterSyntaxError()
{
$twig = $this->getEnvironment(false, [], self::$templates);
@@ -1,18 +0,0 @@
--TEST--
sandbox tag
--DEPRECATION--
Since twig/twig 3.15: The "sandbox" tag is deprecated in "index.twig" at line 2.
--TEMPLATE--
{%- sandbox %}
{%- include "foo.twig" %}
{%- endsandbox %}
--TEMPLATE(foo.twig)--
{{ [a][0] }}
{{ dump([a][0]) }}
--DATA--
return ['a' => 'b']
--CONFIG--
return ['autoescape' => false, 'debug' => true]
--EXPECT--
b
string(1) "b"
@@ -1,11 +0,0 @@
--TEST--
sandbox tag
--TEMPLATE--
{%- sandbox %}
{%- include "foo.twig" %}
a
{%- endsandbox %}
--TEMPLATE(foo.twig)--
foo
--EXCEPTION--
Twig\Error\SyntaxError: Only "include" tags are allowed within a "sandbox" section in "index.twig" at line 4.
@@ -1,14 +0,0 @@
--TEST--
sandbox tag
--TEMPLATE--
{%- sandbox %}
{%- include "foo.twig" %}
{% if 1 %}
{%- include "foo.twig" %}
{% endif %}
{%- endsandbox %}
--TEMPLATE(foo.twig)--
foo
--EXCEPTION--
Twig\Error\SyntaxError: Only "include" tags are allowed within a "sandbox" section in "index.twig" at line 5.
@@ -1,26 +0,0 @@
--TEST--
sandbox tag
--DEPRECATION--
Since twig/twig 3.15: The "sandbox" tag is deprecated in "index.twig" at line 2.
Since twig/twig 3.15: The "sandbox" tag is deprecated in "index.twig" at line 6.
Since twig/twig 3.15: The "sandbox" tag is deprecated in "index.twig" at line 11.
--TEMPLATE--
{%- sandbox %}
{%- include "foo.twig" %}
{%- endsandbox %}
{%- sandbox %}
{%- include "foo.twig" %}
{%- include "foo.twig" %}
{%- endsandbox %}
{%- sandbox %}{% include "foo.twig" %}{% endsandbox %}
--TEMPLATE(foo.twig)--
foo
--DATA--
return []
--EXPECT--
foo
foo
foo
foo