mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-26 20:04:58 +01:00
[tainting] improve twig template names resolving (#122)
This commit is contained in:
parent
f5e4b97c53
commit
a7d3a76ca0
@ -17,6 +17,18 @@ class TwigUtils
|
||||
{
|
||||
public static function extractTemplateNameFromExpression(Expr $templateName, StatementsSource $source): string
|
||||
{
|
||||
return self::resolveStringFromExpression($templateName, $source);
|
||||
}
|
||||
|
||||
private static function resolveStringFromExpression(Expr $templateName, StatementsSource $source): string
|
||||
{
|
||||
if ($templateName instanceof Expr\BinaryOp\Concat) {
|
||||
$right = self::resolveStringFromExpression($templateName->right, $source);
|
||||
$left = self::resolveStringFromExpression($templateName->left, $source);
|
||||
|
||||
return $left.$right;
|
||||
}
|
||||
|
||||
if ($templateName instanceof Variable) {
|
||||
$type = $source->getNodeTypeProvider()->getType($templateName) ?? new Union([new TNull()]);
|
||||
$templateName = array_values($type->getAtomicTypes())[0];
|
||||
|
@ -50,6 +50,8 @@ class TwigUtilsTest extends TestCase
|
||||
['dummy("expected.twig");'],
|
||||
['dummy(\'expected.twig\');'],
|
||||
['$a = "expected.twig"; dummy($a);'],
|
||||
['$a = "expected"; $b = ".twig"; dummy($a.$b);'],
|
||||
['$a = "pected"; dummy("ex".$a.".twig");'],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user