Issue #3457168 by raphaelbertrand, gauravvvv, bbrala, longwave: Since twig/twig 3.9: error with "twig_escape_filter" function usage in /core/lib/Drupal/Core/Template/TwigExtension.php
(cherry picked from commit 128310c8c9
)
merge-requests/9680/head
parent
f3d6416752
commit
e51c4c7178
|
@ -23,6 +23,7 @@ use Twig\Node\Expression\ConstantExpression;
|
|||
use Twig\Node\Node;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\Runtime\EscaperRuntime;
|
||||
|
||||
/**
|
||||
* A class providing Drupal Twig extensions.
|
||||
|
@ -461,7 +462,7 @@ class TwigExtension extends AbstractExtension {
|
|||
if ($strategy == 'html') {
|
||||
return Html::escape($return);
|
||||
}
|
||||
return twig_escape_filter($env, $return, $strategy, $charset, $autoescape);
|
||||
return $env->getRuntime(EscaperRuntime::class)->escape($arg, $strategy, $charset, $autoescape);
|
||||
}
|
||||
|
||||
// This is a normal render array, which is safe by definition, with
|
||||
|
|
|
@ -126,4 +126,17 @@ class TwigExtensionTest extends BrowserTestBase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if Drupal html strategy is done and the fallback to Twig itself works.
|
||||
*/
|
||||
public function testRenderStrategies(): void {
|
||||
/** @var \Drupal\Core\Template\TwigExtension $extension */
|
||||
$extension = \Drupal::service('twig.extension');
|
||||
/** @var \Drupal\Core\Template\TwigEnvironment $twig */
|
||||
$twig = \Drupal::service('twig');
|
||||
|
||||
$this->assertSame('test&', $extension->escapeFilter($twig, 'test&'), 'TwigExtension::escapeFilter() renders escaped & when strategy is html (default).');
|
||||
$this->assertSame('test\u0026', $extension->escapeFilter($twig, 'test&', 'js'), 'TwigExtension::escapeFilter() renders escaped & when strategy is js.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue