Skip to content

Commit 03ef568

Browse files
authored
[BUGFIX] Ensure valid name for cache classes (#1268)
Due to refactorings in the cache layer of Fluid, which were necessary to make cache warmup feasible, the cache identifiers have changed with Fluid 5. This currently leads to parse errors when a template name starts with a number because the associated cache file and most importantly the generated PHP class name also starts with that number, which isn't allowed in PHP. This patch addresses that issue by prepending "template_" to cache identifiers. Other special characters are already dealt with in `TemplateCompiler`, so we only need to ensure that the identifier starts with an alpha-character. Resolves: #1266
1 parent 18048d9 commit 03ef568

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/View/TemplatePaths.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public function getTemplateSource(?string $controller = 'Default', ?string $acti
422422
/**
423423
* Returns a unique identifier for the given file in the format
424424
* <FileName>_<hash>
425-
* The SH1 hash is a checksum that is based on the file path and last modification date
425+
* The hash is a checksum that is based on the file path and last modification date
426426
*/
427427
protected function createIdentifierForFile(?string $pathAndFilename): string
428428
{
@@ -432,7 +432,7 @@ protected function createIdentifierForFile(?string $pathAndFilename): string
432432
$templateModifiedTimestamp = filemtime($pathAndFilename);
433433
$prefix = str_replace('.', '_', basename($pathAndFilename));
434434
}
435-
return sprintf('%s_%s', $prefix, hash('xxh3', $pathAndFilename . '|' . $templateModifiedTimestamp));
435+
return sprintf('template_%s_%s', $prefix, hash('xxh3', $pathAndFilename . '|' . $templateModifiedTimestamp));
436436
}
437437

438438
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
template name starting with non-alpha character and containing invalid characters

tests/Unit/View/TemplatePathsTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,19 @@ public static function getTemplateIdentifierDataProvider(): array
171171
__DIR__ . '/Fixtures',
172172
'ARandomController',
173173
'TestTemplate',
174-
'TestTemplate_html_',
174+
'template_TestTemplate_html_',
175175
],
176176
[
177177
__DIR__ . '/Fixtures',
178178
'',
179179
'UnparsedTemplateFixture',
180-
'UnparsedTemplateFixture_html_',
180+
'template_UnparsedTemplateFixture_html_',
181+
],
182+
[
183+
__DIR__ . '/Fixtures',
184+
'',
185+
'123Template-foo$=bar',
186+
'template_123Template-foo$=bar_', // Special characters are removed in template compiler
181187
],
182188
];
183189
}

0 commit comments

Comments
 (0)