diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index 912cea8..1bf2a57 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -237,17 +237,15 @@ function twig_drupal_escape_filter(\Twig_Environment $env, $string, $strategy = // We have a string or an object converted to a string: Autoescape it! if (isset($return)) { - if ($strategy != 'html') { - // Drupal only supports the HTML escaping strategy, so provide a - // fallback for other strategies. - // @todo Add an optional strategy parameter to SafeMarkup function calls, - // to avoid this when it is already safe for this strategy. - return twig_escape_filter($env, $return, $strategy, $charset, $autoescape); + if ($autoescape && SafeMarkup::isSafe($return, $strategy) { + return $return; } - if (!SafeMarkup::isSafe($return)) { + // Drupal only supports the HTML escaping strategy, so provide a + // fallback for other strategies. + if ($strategy == 'html') { return String::checkPlain($return); } - return $return; + return twig_escape_filter($env, $return, $strategy, $charset, $autoescape); } // This is a normal render array, which is safe by definition.