From 693693ba3a4a9e73fc3a0e5f4961bf3d23a7c46d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 7 Aug 2024 18:58:14 +0200 Subject: [PATCH 1/2] Mark ConstantExpression as @final --- src/Node/Expression/ConstantExpression.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Node/Expression/ConstantExpression.php b/src/Node/Expression/ConstantExpression.php index 7ddbcc6fa99..2a8909d5469 100644 --- a/src/Node/Expression/ConstantExpression.php +++ b/src/Node/Expression/ConstantExpression.php @@ -14,6 +14,9 @@ use Twig\Compiler; +/** + * @final + */ class ConstantExpression extends AbstractExpression { public function __construct($value, int $lineno) From 230e31d384b2661289ce1f3dcd7574c2fbea9274 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 7 Aug 2024 19:06:26 +0200 Subject: [PATCH 2/2] Add a recipe about how to mark a node as safe --- CHANGELOG | 1 + doc/recipes.rst | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 40fc1b4a0ec..24fc6e7d364 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ # 3.11.0 (2024-XX-XX) + * Mark `ConstantExpression` as being `@final` * Add the `find` filter * Fix optimizer mode validation in `OptimizerNodeVisitor` * Add the possibility to yield from a generator in `PrintNode` diff --git a/doc/recipes.rst b/doc/recipes.rst index b342457edf2..c091d34fc63 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -528,4 +528,15 @@ include in your templates: 'tag_variable' => ['{[', ']}'], ])); +Marking a Node as being safe +---------------------------- + +When using the escaper extension, you might want to mark some nodes as being +safe to avoid any escaping. You can do so by wrapping your expression with a +``RawFilter`` node:: + + use Twig\Node\Expression\Filter\RawFilter; + + $safeExpr = new RawFilter(new YourSafeNode()); + .. _callback: https://www.php.net/manual/en/function.is-callable.php