diff --git a/src/Core/Parser/SyntaxTree/ObjectAccessorNode.php b/src/Core/Parser/SyntaxTree/ObjectAccessorNode.php index 0818b692a..3c4420bc3 100644 --- a/src/Core/Parser/SyntaxTree/ObjectAccessorNode.php +++ b/src/Core/Parser/SyntaxTree/ObjectAccessorNode.php @@ -11,6 +11,7 @@ use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3Fluid\Fluid\Core\Variables\InvalidVariableIdentifierException; /** * A node which handles object access. This means it handles structures like {object.accessor.bla} @@ -34,6 +35,12 @@ final class ObjectAccessorNode extends AbstractNode */ public function __construct(string $objectPath) { + // TODO consider removing this exception in later Fluid versions. For now it allows the + // TemplateValidator to find occurrances of variables starting with "_" in templates, + // which are no longer allowed since Fluid 5. + if (str_starts_with($objectPath, '_') && $objectPath !== '_all') { + throw new InvalidVariableIdentifierException('Variable identifiers cannot start with a "_": ' . $objectPath, 1765900762); + } $this->objectPath = $objectPath; } diff --git a/tests/Functional/Fixtures/Validation/AccessToInvalidVariableName.fluid.html b/tests/Functional/Fixtures/Validation/AccessToInvalidVariableName.fluid.html new file mode 100644 index 000000000..04b2022b7 --- /dev/null +++ b/tests/Functional/Fixtures/Validation/AccessToInvalidVariableName.fluid.html @@ -0,0 +1 @@ +{_something.sub} diff --git a/tests/Functional/Validation/TemplateValidatorTest.php b/tests/Functional/Validation/TemplateValidatorTest.php index 2fca36b6d..816bf6df1 100644 --- a/tests/Functional/Validation/TemplateValidatorTest.php +++ b/tests/Functional/Validation/TemplateValidatorTest.php @@ -26,6 +26,7 @@ public static function validatorFindsParseErrorsDataProvider(): array [$fixturePath . 'InvalidNamespace.fluid.html', 'Unknown Namespace: foo', 0], [$fixturePath . 'RequiredArgumentMissing.fluid.html', 'Required argument "each" was not supplied.', 1237823699], [$fixturePath . 'RedefinedComponentArgument.fluid.html', 'Template argument "foo" has been defined multiple times.', 1744908509], + [$fixturePath . 'AccessToInvalidVariableName.fluid.html', 'Variable identifiers cannot start with a "_": _something.sub', 1765900762], ]; }