From e58b2feda24b78f7e76503fbd0a6ca0640a51d9b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Apr 2024 12:04:02 -0400 Subject: [PATCH 01/11] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 38421d5f2..34642cade 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ * Deprecate all internal extension functions in favor of methods on the extension classes * Mark all extension functions as @internal * Add SourcePolicyInterface to selectively enable the Sandbox based on a template's Source + * Throw a proper Twig exception when using cycle on an empty array # 3.8.0 (2023-11-21) From 47857eebb197745f66369b76c044a2359e3cc5b9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Apr 2024 12:04:21 -0400 Subject: [PATCH 02/11] Prepare the 3.9.0 release --- CHANGELOG | 2 +- src/Environment.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 34642cade..9ff2ead3d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -# 3.9.0 (2024-XX-XX) +# 3.9.0 (2024-04-16) * Add support for PHP 8.4 * Deprecate AbstractNodeVisitor diff --git a/src/Environment.php b/src/Environment.php index 3422ca49f..f18edf2fc 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - public const VERSION = '3.9.0-DEV'; + public const VERSION = '3.9.0'; public const VERSION_ID = 30900; public const MAJOR_VERSION = 3; public const MINOR_VERSION = 9; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; private $charset; private $loader; From 2105d659574211ce6da200da5867180a1e00c1ef Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Apr 2024 12:05:55 -0400 Subject: [PATCH 03/11] Bump version --- CHANGELOG | 4 ++++ src/Environment.php | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9ff2ead3d..ef5b57fc2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +# 3.9.1 (2024-XX-XX) + + * n/a + # 3.9.0 (2024-04-16) * Add support for PHP 8.4 diff --git a/src/Environment.php b/src/Environment.php index f18edf2fc..8b9c024c9 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - public const VERSION = '3.9.0'; - public const VERSION_ID = 30900; + public const VERSION = '3.9.1-DEV'; + public const VERSION_ID = 30901; public const MAJOR_VERSION = 3; public const MINOR_VERSION = 9; - public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 1; + public const EXTRA_VERSION = 'DEV'; private $charset; private $loader; From 64cebe0e0b102e81b14d7008fe05e4ad8d06058c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Apr 2024 17:30:40 -0400 Subject: [PATCH 04/11] Fix CaptureNode for some use cases --- CHANGELOG | 2 +- src/Node/MacroNode.php | 5 ++++- tests/Fixtures/macros/macro_with_capture.test | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/Fixtures/macros/macro_with_capture.test diff --git a/CHANGELOG b/CHANGELOG index ef5b57fc2..07490c531 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ # 3.9.1 (2024-XX-XX) - * n/a + * Fix missing `$blocks` variable in `CaptureNode` # 3.9.0 (2024-04-16) diff --git a/src/Node/MacroNode.php b/src/Node/MacroNode.php index e44150f52..761ef55d2 100644 --- a/src/Node/MacroNode.php +++ b/src/Node/MacroNode.php @@ -79,6 +79,9 @@ class MacroNode extends Node ; } + $node = new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag); + $node->setAttribute('with_blocks', true); + $compiler ->write('') ->string(self::VARARGS_NAME) @@ -88,7 +91,7 @@ class MacroNode extends Node ->write("]);\n\n") ->write("\$blocks = [];\n\n") ->write('return ') - ->subcompile(new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag)) + ->subcompile($node) ->raw("\n") ->outdent() ->write("}\n\n") diff --git a/tests/Fixtures/macros/macro_with_capture.test b/tests/Fixtures/macros/macro_with_capture.test new file mode 100644 index 000000000..f67a7fcdb --- /dev/null +++ b/tests/Fixtures/macros/macro_with_capture.test @@ -0,0 +1,14 @@ +--TEST-- +macro +--TEMPLATE-- +{{ _self.some_macro() }} + +{% macro some_macro() %} + {% apply spaceless %} + {% if true %}foo{% endif %} + {% endapply %} +{% endmacro %} +--DATA-- +return [] +--EXPECT-- +foo From 664647f46bf68a98cf5af27b42de8017a3e2d878 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 17 Apr 2024 05:00:00 -0400 Subject: [PATCH 05/11] Prepare the 3.9.1 release --- CHANGELOG | 2 +- src/Environment.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 07490c531..4c4de1e52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -# 3.9.1 (2024-XX-XX) +# 3.9.1 (2024-04-17) * Fix missing `$blocks` variable in `CaptureNode` diff --git a/src/Environment.php b/src/Environment.php index 8b9c024c9..b7d251be9 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - public const VERSION = '3.9.1-DEV'; + public const VERSION = '3.9.1'; public const VERSION_ID = 30901; public const MAJOR_VERSION = 3; public const MINOR_VERSION = 9; public const RELEASE_VERSION = 1; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; private $charset; private $loader; From 0b4269e6c13e0e2802d531dfb618ad00a4b72d47 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 17 Apr 2024 05:00:49 -0400 Subject: [PATCH 06/11] Bump version --- CHANGELOG | 4 ++++ src/Environment.php | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4c4de1e52..a0e0694c1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +# 3.9.2 (2024-XX-XX) + + * n/a + # 3.9.1 (2024-04-17) * Fix missing `$blocks` variable in `CaptureNode` diff --git a/src/Environment.php b/src/Environment.php index b7d251be9..09cd0a6d6 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - public const VERSION = '3.9.1'; - public const VERSION_ID = 30901; + public const VERSION = '3.9.2-DEV'; + public const VERSION_ID = 30902; public const MAJOR_VERSION = 3; public const MINOR_VERSION = 9; - public const RELEASE_VERSION = 1; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 2; + public const EXTRA_VERSION = 'DEV'; private $charset; private $loader; From 5d903b63258761b2af99134d3c9e1018c85f155f Mon Sep 17 00:00:00 2001 From: benedikt brunner <122370755+Benedikt-Brunner@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:41:53 +0000 Subject: [PATCH 07/11] Require correct twig core version --- extra/intl-extra/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/intl-extra/composer.json b/extra/intl-extra/composer.json index c39239164..a46eada31 100644 --- a/extra/intl-extra/composer.json +++ b/extra/intl-extra/composer.json @@ -16,7 +16,7 @@ ], "require": { "php": ">=7.2.5", - "twig/twig": "^3.0", + "twig/twig": "^3.9", "symfony/intl": "^5.4|^6.4|^7.0" }, "require-dev": { From 3ca9685f58dce37fba0f850c8c2e5b41a99b0776 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 17 Apr 2024 08:50:46 -0400 Subject: [PATCH 08/11] Fix usage of display_end hook --- CHANGELOG | 2 +- src/Node/ModuleNode.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a0e0694c1..26966d282 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ # 3.9.2 (2024-XX-XX) - * n/a + * Fix usage of display_end hook # 3.9.1 (2024-04-17) diff --git a/src/Node/ModuleNode.php b/src/Node/ModuleNode.php index 10e94f681..df407caf0 100644 --- a/src/Node/ModuleNode.php +++ b/src/Node/ModuleNode.php @@ -336,12 +336,15 @@ final class ModuleNode extends Node $compiler->raw('$this->getParent($context)'); } $compiler->raw("->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks));\n"); - } else { + } + + $compiler->subcompile($this->getNode('display_end')); + + if (!$this->hasNode('parent')) { $compiler->write("return; yield '';\n"); // ensure at least one yield call even for templates with no output } $compiler - ->subcompile($this->getNode('display_end')) ->outdent() ->write("}\n\n") ; From 856cb5a6cfd6f3e4dc1f6c9a8f54e259503f7cf3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 17 Apr 2024 10:16:01 -0400 Subject: [PATCH 09/11] Prepare the 3.9.2 release --- CHANGELOG | 2 +- src/Environment.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 26966d282..1c88f2ed0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -# 3.9.2 (2024-XX-XX) +# 3.9.2 (2024-04-17) * Fix usage of display_end hook diff --git a/src/Environment.php b/src/Environment.php index 09cd0a6d6..540ee02d6 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - public const VERSION = '3.9.2-DEV'; + public const VERSION = '3.9.2'; public const VERSION_ID = 30902; public const MAJOR_VERSION = 3; public const MINOR_VERSION = 9; public const RELEASE_VERSION = 2; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; private $charset; private $loader; From c145871023dcc6c2117f8af3aa691f75d0924e01 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 17 Apr 2024 10:17:23 -0400 Subject: [PATCH 10/11] Bump version --- CHANGELOG | 4 ++++ src/Environment.php | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1c88f2ed0..950346968 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +# 3.9.3 (2024-XX-XX) + + * n/a + # 3.9.2 (2024-04-17) * Fix usage of display_end hook diff --git a/src/Environment.php b/src/Environment.php index 540ee02d6..c761bdb41 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - public const VERSION = '3.9.2'; - public const VERSION_ID = 30902; + public const VERSION = '3.9.3-DEV'; + public const VERSION_ID = 30903; public const MAJOR_VERSION = 3; public const MINOR_VERSION = 9; - public const RELEASE_VERSION = 2; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 3; + public const EXTRA_VERSION = 'DEV'; private $charset; private $loader; From 1170144f66d5c11123668d52f64ae46a2a287d8e Mon Sep 17 00:00:00 2001 From: Francesco Sardara Date: Wed, 17 Apr 2024 18:07:44 +0200 Subject: [PATCH 11/11] Add twig_escape_filter_is_safe() as deprecated. --- src/Resources/escaper.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Resources/escaper.php b/src/Resources/escaper.php index ea3778035..bc93331a6 100644 --- a/src/Resources/escaper.php +++ b/src/Resources/escaper.php @@ -11,9 +11,11 @@ use Twig\Environment; use Twig\Extension\EscaperExtension; +use Twig\Node\Node; /** * @internal + * * @deprecated since Twig 3.9 */ function twig_raw_filter($string) @@ -25,6 +27,7 @@ function twig_raw_filter($string) /** * @internal + * * @deprecated since Twig 3.9 */ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) @@ -33,3 +36,15 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char return EscaperExtension::escape($env, $string, $strategy, $charset, $autoescape); } + +/** + * @internal + * + * @deprecated since Twig 3.9 + */ +function twig_escape_filter_is_safe(Node $filterArgs) +{ + trigger_deprecation('twig/twig', '3.9', 'Using the internal "%s" function is deprecated.', __FUNCTION__); + + return EscaperExtension::escapeFilterIsSafe($filterArgs); +}