Repository navigation
Normalize the template name in FilesystemLoader::getSourceContext() - #4985
Merged
fabpot merged 2 commits intoNov 18, 2026
Merged
Conversation
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
COil
reviewed
Oct 8, 2026
| } | ||
|
|
||
| return new Source(file_get_contents($path), $name, $path); | ||
| return new Source(file_get_contents($path), $this->normalizeName($name), $path); |
There was a problem hiding this comment.
Thanks, I didn't see that there was already a normalize function. Let me try this.
There was a problem hiding this comment.
I had to copy the private normalizeName() function in my custom FilesystemLoader class, but it works.
Contributor
|
Thank you @KalimeroMK. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the root cause of symfony/symfony#61099:
findTemplate()normalizes names for lookup andgetCacheKey()is path-based, so the same template gets compiled through different spellings — e.g.App\Controller\HomeAction.html.twigat runtime vsApp/Controller/HomeAction.html.twigfrom CLI cache warmup — but theSourcekept the name as passed, makinggetTemplateName()(and_self) depend on which spelling compiled the template first. TheSourcenow always carries the canonical forward-slash name. Includes a regression test.