diff -u b/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php --- b/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -345,6 +345,22 @@ } /** + * Provides a passthrough filter for trans. + * + * @param mixed $string + * The value. + * + * @return string|null + * The string, XSS admin filtered if not safe. + */ + public function passthrough($string) { + if (!SafeMarkup::isSafe($string)) { + $string = Xss::filterAdmin($string); + } + return $string; + } + + /** * Overrides twig_escape_filter(). * * Replacement function for Twig's escape filter. @@ -371,22 +387,6 @@ } /** - * Provides a passthrough filter for trans. - * - * @param mixed $string - * The value. - * - * @return string|null - * The string, XSS admin filtered if not safe. - */ - public function passthrough($string) { - if (!SafeMarkup::isSafe($string)) { - $string = Xss::filterAdmin($string); - } - return $string; - } - - /** * Overrides twig_escape_filter(). * * Replacement function for Twig's escape filter. diff -u b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig --- b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig +++ b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig @@ -1,10 +1,10 @@
{{ message|testfilter }}
- + {# + The placeholder and passthrough filters should only be used in trans tags + but their effects need to be tested outside trans tags. + #}
{{ placeholder_text|placeholder }}
@@ -16 +16 @@ - \ No newline at end of file + diff -u b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig --- b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig +++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.trans.html.twig @@ -54,7 +54,11 @@
{% trans %} - {# Note this should never be necessary: we can just print the safe string in the template directly. #} + {# + Just for illustration purposes we pass in a safe string that won't be + filtered. This should never be necessary as instead, we could just print + the safe string in the template directly. + #} Safe: {{ safe_string|passthrough }} {% endtrans %}