Twig cache contains absolute paths
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 8.4k
- Forks
- 1.3k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 37
Description
I noticed this in a Symfony app but while trying to see where the error was, I noticed that it's actually Twig core behaviour.
Yet reproducing it is probably easier using Symfony Flex:
composer create-project symfony/skeleton . 4.4.*composer req twigAPP_ENV=prod ./bin/console cache:warmup
You'll see that the cache contains files along the following lines:
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* @Framework/Form/time_widget.html.php */
class __TwigTemplate_884348209061bf9effea81fda27c890a9a31886d0f62de99211558053cc7ec90 extends \Twig\Template
{
private $source;
private $macros = [];
[...]
public function getSourceContext()
{
return new Source("", "@Framework/Form/time_widget.html.php", "/absolute/path/to/project/vendor/symfony/framework-bundle/Resources/views/Form/time_widget.html.php");
}
}
Actually this is the only place where I noticed absolute paths in a typical Symfony cache which causes issues if e.g. you have a chrooted SSH user and a different path in the web process.
Not sure how to fix it though. The FilesystemLoader seems to provide absolute file paths by contract.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Symfony Flex commands in the report and inspect the generated cache files. Start by reading the FilesystemLoader contract and tracing how its absolute path reaches Source in the cached template. Done means agreeing on and testing a cache-path behavior that works across the different process paths described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100