From 79dadd777c2d7a7cc8c836c51e24d4034ca98c0c Mon Sep 17 00:00:00 2001 From: Zoran Shefot Bogoevski <24772657+KalimeroMK@users.noreply.github.com> Date: Thu, 8 Oct 2026 07:16:05 +0200 Subject: [PATCH 1/2] Normalize the template name in FilesystemLoader::getSourceContext() findTemplate() normalizes names for lookup and getCacheKey() is path-based, so the same template can be compiled through different spellings (e.g. 'App\\Controller\\Foo.html.twig' at runtime vs 'App/Controller/Foo.html.twig' from CLI cache warmup). The Source kept the name as passed, making getTemplateName() (and `_self`) depend on which spelling compiled the template first. Normalize the name stored in the Source so it is always the canonical forward-slash form. Refs symfony/symfony#61099 --- src/Loader/FilesystemLoader.php | 2 +- tests/Loader/FilesystemTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Loader/FilesystemLoader.php b/src/Loader/FilesystemLoader.php index cf2b653e18d..bca2bd0312d 100644 --- a/src/Loader/FilesystemLoader.php +++ b/src/Loader/FilesystemLoader.php @@ -138,7 +138,7 @@ public function getSourceContext(string $name): Source return new Source('', $name, ''); } - return new Source(file_get_contents($path), $name, $path); + return new Source(file_get_contents($path), $this->normalizeName($name), $path); } public function getCacheKey(string $name): string diff --git a/tests/Loader/FilesystemTest.php b/tests/Loader/FilesystemTest.php index 9dd208c6d48..f0b5f985db2 100644 --- a/tests/Loader/FilesystemTest.php +++ b/tests/Loader/FilesystemTest.php @@ -36,6 +36,12 @@ public function testGetSourceContext(): void $this->assertEquals(realpath($path.'/errors/index.html'), realpath($loader->getSourceContext('errors/index.html')->getPath())); } + public function testGetSourceContextNormalizesName(): void + { + $loader = new FilesystemLoader([__DIR__.'/../Fixtures']); + $this->assertSame('errors/index.html', $loader->getSourceContext('errors\index.html')->getName()); + } + /** * @dataProvider getSecurityTests */ From 5bafb988d9a3b360df7634160b895408d7ac91e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 18 Nov 2026 07:22:29 +0000 Subject: [PATCH 2/2] Add a CHANGELOG entry for FilesystemLoader template name normalization --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 9ba6322173c..4292a2d222a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ * Fix the `loop` variable being undefined when used in the sequence of a nested `for` tag * Reject a deprecated `Template` instance created by another environment in `Environment::resolveTemplate()` * Fix a compilation error inside an `autoescape` tag leaking its escaping strategy into the next compiled template + * Fix `FilesystemLoader` template names depending on the slash style used to load a template first * Fix the non-selected branch of a `guard` tag registering its parent, blocks, and macros * Speed up reading object attributes backed by getters or class constants * Fix the sandbox not reporting the line of a rejected `guard` tag