Merge branch 'support/3.0' into develop

# Conflicts:
#	datamodels/2.x/itop-portal-base/portal/src/Twig/AppExtension.php
#	test/twig/test.html
#	test/twig/test.html.twig
This commit is contained in:
Eric Espie
2022-11-30 13:57:28 +01:00
4 changed files with 130 additions and 66 deletions

View File

@@ -165,16 +165,53 @@ class AppExtension extends AbstractExtension
//since 2.7.7 3.0.2 3.1.0 N°4867 "Twig content not allowed" error when use the extkey widget search icon in the user portal
//overwrite native twig filter : disable use of 'system' filter
$filters[] = new TwigFilter('filter', function ($array, $arrow) {
if ($arrow == 'system'){
return json_encode($array);
$ret = $this->SanitizeFilter($array, $arrow);
if ($ret !== false) {
return [$ret];
}
$oEnv = new Environment(new FilesystemLoader());
return twig_array_filter($oEnv, $array, $arrow);
return twig_array_filter($oEnv, $array, $arrow);
});
$filters[] = new TwigFilter('map', function ($array, $arrow) {
$ret = $this->SanitizeFilter($array, $arrow);
if ($ret !== false) {
return [$ret];
}
$oEnv = new Environment(new FilesystemLoader());
return twig_array_map($oEnv, $array, $arrow);
});
$filters[] = new TwigFilter('reduce', function ($array, $arrow, $initial = null) {
$ret = $this->SanitizeFilter($array, $arrow);
if ($ret !== false) {
return $ret;
}
// reduce return mixed results not only arrays
$oEnv = new Environment(new FilesystemLoader());
return twig_array_reduce($oEnv, $array, $arrow, $initial);
});
$filters[] = new TwigFilter('sort', function ($array, $arrow, $initial = null) {
$ret = $this->SanitizeFilter($array, $arrow);
if ($ret !== false) {
return $ret;
}
// reduce return mixed results not only arrays
$oEnv = new Environment(new FilesystemLoader());
return twig_array_reduce($oEnv, $array, $arrow, $initial);
});
return $filters;
}
private function SanitizeFilter($array, $arrow)
{
if (is_string($arrow)) {
if (in_array(strtolower($arrow), ['system', 'exec', 'passthru', 'popen'])) {
return json_encode($array);
}
}
return false;
}
/**
* @return array|\Twig\TwigFunction[]|\Twig\TwigFunction[]
*/