diff --git a/core/lib/Drupal/Core/Template/TwigNodeTrans.php b/core/lib/Drupal/Core/Template/TwigNodeTrans.php index 1bacb9e..a7b723a 100644 --- a/core/lib/Drupal/Core/Template/TwigNodeTrans.php +++ b/core/lib/Drupal/Core/Template/TwigNodeTrans.php @@ -82,20 +82,7 @@ public function compile(\Twig_Compiler $compiler) { // Write function closure. $compiler->raw(')'); - // Append translation debug markup, if necessary. - if ($compiler->getEnvironment()->isDebug()) { - $compiler->raw(" . '\n\n'"); - } + // @todo Add debug output, see https://www.drupal.org/node/2512672 // End writing. $compiler->raw(";\n"); diff --git a/core/modules/system/src/Tests/Theme/TwigTransTest.php b/core/modules/system/src/Tests/Theme/TwigTransTest.php index d9d3aa56..1190ab5 100644 --- a/core/modules/system/src/Tests/Theme/TwigTransTest.php +++ b/core/modules/system/src/Tests/Theme/TwigTransTest.php @@ -154,9 +154,12 @@ public function testTwigTransTags() { 'O HAI NU TXTZZZZ.', '{% trans with {"context": "Lolspeak", "langcode": "zz"} %} was successfully translated with context in specified language.' ); - - // Ensure debug output does not print. - $this->checkForDebugMarkup(FALSE); + // Makes sure https://www.drupal.org/node/2489024 doesn't happen without + // twig debug. + $this->assertText( + "Hello kittens - ' . print('I am bad code!') . '", + 'Running php code inside a Twig trans is not possible.' + ); } /** @@ -172,53 +175,6 @@ public function testTwigTransDebug() { // Get page for assertion testing. $this->drupalGet('twig-theme-test/trans', array('language' => \Drupal::languageManager()->getLanguage('xx'))); - - // Ensure debug output is printed. - $this->checkForDebugMarkup(TRUE); - } - - /** - * Tests rendering a placeholder outside of translate. - * - * This test ensures that the security problem described in - * https://www.drupal.org/node/2495179 doesn't exist. - */ - public function testPlaceholderOutsideOfTrans() { - $this->drupalGet(Url::fromRoute('twig_theme_test.placeholder_outside_trans')); - - $script = ''; - $this->assertNoRaw($script); - $this->assertEqual(2, substr_count($this->getRawContent(), '' . SafeMarkup::checkPlain($script) . '')); - } - - /** - * Helper function: test twig debug translation markup. - * - * @param bool $visible - * Toggle determining which assertion to use for test. - */ - protected function checkForDebugMarkup($visible) { - $tests = array( - '{% trans "Hello sun." %}' => '', - '{% trans "Hello sun." with {"context": "Lolspeak"} %}' => '', - '{{ "Hello moon."|trans }}' => '', - '{% trans %} with {% plural %}' => '', - '{{ token }}' => '', - '{{ token|passthrough }}' => '', - '{{ token|placeholder }}' => '', - '{{ complex.tokens }}' => '', - '{% trans with {"context": "Lolspeak"} %}I have context.{% endtrans %}' => '', - '{% trans with {"langcode": "zz"} %}Hello new text.{% endtrans %}' => '', - '{% trans with {"context": "Lolspeak", "langcode": "zz"} %}Hello new text.{% endtrans %}' => '', - ); - foreach ($tests as $test => $markup) { - if ($visible) { - $this->assertRaw($markup, "Twig debug translation markup exists in source for: $test"); - } - else { - $this->assertNoRaw($markup, "Twig debug translation markup does not exist in source for: $test"); - } - } } /** diff --git a/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 index 2f4dda0..16b14dd 100644 --- a/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 @@ -94,3 +94,10 @@ Hello new text. {% endtrans %} + +{# Tests that https://www.drupal.org/node/2489024 doesn't happen without twig debug. #} +
+ '{% trans %} + Hello kittens - ' . print('I am bad code!') . ' + {% endtrans %} +