diff -u b/core/modules/system/src/Tests/Theme/TwigTransTest.php b/core/modules/system/src/Tests/Theme/TwigTransTest.php --- b/core/modules/system/src/Tests/Theme/TwigTransTest.php +++ b/core/modules/system/src/Tests/Theme/TwigTransTest.php @@ -138,9 +138,15 @@ '{{ token }} was successfully translated and prefixed with "@".' ); + // @see \Drupal\Core\Template\TwigNodeTrans::compileString() $this->assertRaw( 'Y U NO LET ME XSS: &"<>', - '{{ token|passthrough }} was successfully translated and prefixed with "!".' + '{{ token|passthrough }} (unsafe) was successfully translated and prefixed with "!".' + ); + + $this->assertRaw( + 'YAY XSS: ', + '{{ token|passthrough }} (safe) was successfully translated and prefixed with "!".' ); $this->assertRaw( @@ -256,6 +262,9 @@ msgid "Admin filtered: !string" msgstr "Y U NO LET ME XSS: !string" +msgid "Safe: !safe_string" +msgstr "YAY XSS: !safe_string" + msgid "Placeholder: %string" msgstr "PLAYSHOLDR: %string" 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 @@ -55,0 +56,6 @@ + {% trans %} + {# Note this should never be necessary: we can just print the safe string in the template directly. #} + Safe: {{ safe_string|passthrough }} + {% endtrans %} + +
only in patch2: unchanged: --- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module +++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module @@ -1,5 +1,7 @@ 'twig_theme_test.php_variables', ); $items['twig_theme_test_trans'] = array( - 'variables' => array(), + 'variables' => array('safe_string' => SafeString::create('')), 'template' => 'twig_theme_test.trans', ); $items['twig_theme_test_placeholder_outside_trans'] = array(