From 1604e6b3ef90fa5de8112b60a2574cce50726b6e Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon@praetorius.me> Date: Sun, 11 Aug 2024 11:43:37 +0200 Subject: [PATCH] [FEATURE] Ignore Fluid syntax error in <f:comment> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch enables a template processor included in Fluid 4 for all Fluid instances in the Core. The template processor strips `<f:comment>` tags from Fluid template strings before the parsing starts. This prevents Fluid errors when invalid Fluid code is used inside `<f:comment>`. Original change in Fluid: https://github.com/TYPO3/Fluid/commit/faad81a9f5d991d688e1d4c673e0d7aaf41a7e94 Resolves: #104904 Releases: main Change-Id: Ieebb60ee21ae9f8d6f168e75b9fd22a7103a5f6a Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86012 Reviewed-by: Guido Schmechel <guido.schmechel@brandung.de> Tested-by: Andreas Kienast <a.fernandez@scripting-base.de> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Simon Praetorius <simon@praetorius.me> Reviewed-by: Simon Praetorius <simon@praetorius.me> Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Andreas Kienast <a.fernandez@scripting-base.de> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: core-ci <typo3@b13.com> --- .../Configuration/DefaultConfiguration.php | 1 + ...04904-IgnoreFluidSyntaxErrorInFComment.rst | 30 +++++++++++++++++++ .../Rendering/RenderingContextFactory.php | 2 ++ .../sysext/fluid/Configuration/Services.yaml | 4 +++ 4 files changed, 37 insertions(+) create mode 100644 typo3/sysext/core/Documentation/Changelog/13.3/Feature-104904-IgnoreFluidSyntaxErrorInFComment.rst diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php index 712dc2496108..d65fcee76c5e 100644 --- a/typo3/sysext/core/Configuration/DefaultConfiguration.php +++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php @@ -364,6 +364,7 @@ return [ \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\EscapingModifierTemplateProcessor::class, \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\PassthroughSourceModifierTemplateProcessor::class, \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor::class, + \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\RemoveCommentsTemplateProcessor::class, ], 'expressionNodeTypes' => [ \TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\CastingExpressionNode::class, diff --git a/typo3/sysext/core/Documentation/Changelog/13.3/Feature-104904-IgnoreFluidSyntaxErrorInFComment.rst b/typo3/sysext/core/Documentation/Changelog/13.3/Feature-104904-IgnoreFluidSyntaxErrorInFComment.rst new file mode 100644 index 000000000000..eb050920ba8e --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/13.3/Feature-104904-IgnoreFluidSyntaxErrorInFComment.rst @@ -0,0 +1,30 @@ +.. include:: /Includes.rst.txt + +.. _feature-104904-1726049662: + +=========================================================== +Feature: #104904 - Ignore Fluid syntax error in <f:comment> +=========================================================== + +See :issue:`104904` + +Description +=========== + +Fluid 4 brings a new template processor +:php:`TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\RemoveCommentsTemplateProcessor` +which removes Fluid comments created with :html:`<f:comment>` from the template source +string before the parsing process starts. It retains the original line breaks to ensure +that error messages still refer to the correct line in the template. + +By applying this template processor to all Fluid instances in the Core, it is now +possible to use invalid Fluid code inside :html:`<f:comment>` without triggering a Fluid error. + + +Impact +====== + +This feature is helpful during template development because developers don't need to +take care for commented-out code being valid Fluid code. + +.. index:: Fluid, ext:fluid diff --git a/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContextFactory.php b/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContextFactory.php index a7a43402583e..e5417a4247d4 100644 --- a/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContextFactory.php +++ b/typo3/sysext/fluid/Classes/Core/Rendering/RenderingContextFactory.php @@ -27,6 +27,7 @@ use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface; use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\EscapingModifierTemplateProcessor; use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor; use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\PassthroughSourceModifierTemplateProcessor; +use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\RemoveCommentsTemplateProcessor; use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessorInterface; /** @@ -68,6 +69,7 @@ final readonly class RenderingContextFactory new EscapingModifierTemplateProcessor(), new PassthroughSourceModifierTemplateProcessor(), new NamespaceDetectionTemplateProcessor(), + new RemoveCommentsTemplateProcessor(), ]; } else { foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors'] as $className) { diff --git a/typo3/sysext/fluid/Configuration/Services.yaml b/typo3/sysext/fluid/Configuration/Services.yaml index aed2f9271518..ee83ea94a681 100644 --- a/typo3/sysext/fluid/Configuration/Services.yaml +++ b/typo3/sysext/fluid/Configuration/Services.yaml @@ -39,3 +39,7 @@ services: TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor: public: true shared: false + TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\RemoveCommentsTemplateProcessor: + public: true + shared: false + -- GitLab