Loading core/lib/Drupal/Core/Template/TwigExtension.php +6 −2 Changes for core/lib/Drupal/Core/Template/TwigExtension.php: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -534,7 +534,7 @@ public function renderVar($arg) { * * @param \Twig_Environment $env * A Twig_Environment instance. * @param mixed[]|\Traversable $value * @param mixed[]|\Traversable|NULL $value * The pieces to join. * @param string $glue * The delimiter with which to join the string. Defaults to an empty string. Loading @@ -545,10 +545,14 @@ public function renderVar($arg) { * The strings joined together. */ public function safeJoin(\Twig_Environment $env, $value, $glue = '') { if ($value instanceof \Traversable) { $value = iterator_to_array($value, false); } return implode($glue, array_map(function($item) use ($env) { // If $item is not marked safe then it will be escaped. return $this->escapeFilter($env, $item, 'html', NULL, TRUE); }, $value)); }, (array) $value)); } } core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php +14 −0 Changes for core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -200,6 +200,20 @@ public function testSafeJoin() { ]; $result = $twig_extension->safeJoin($twig_environment, $items, '<br/>'); $this->assertEquals('<em>will be escaped</em><br/><em>will be markup</em><br/><strong>will be rendered</strong>', $result); // Ensure safe_join Twig filter supports Traversable variables. $items = new \ArrayObject([ '<em>will be escaped</em>', $markup, ['#markup' => '<strong>will be rendered</strong>'], ]); $result = $twig_extension->safeJoin($twig_environment, $items, ', '); $this->assertEquals('<em>will be escaped</em>, <em>will be markup</em>, <strong>will be rendered</strong>', $result); // Ensure safe_join Twig filter supports empty variables. $items = NULL; $result = $twig_extension->safeJoin($twig_environment, $items, '<br>'); $this->assertEmpty($result); } /** Loading Loading
core/lib/Drupal/Core/Template/TwigExtension.php +6 −2 Changes for core/lib/Drupal/Core/Template/TwigExtension.php: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -534,7 +534,7 @@ public function renderVar($arg) { * * @param \Twig_Environment $env * A Twig_Environment instance. * @param mixed[]|\Traversable $value * @param mixed[]|\Traversable|NULL $value * The pieces to join. * @param string $glue * The delimiter with which to join the string. Defaults to an empty string. Loading @@ -545,10 +545,14 @@ public function renderVar($arg) { * The strings joined together. */ public function safeJoin(\Twig_Environment $env, $value, $glue = '') { if ($value instanceof \Traversable) { $value = iterator_to_array($value, false); } return implode($glue, array_map(function($item) use ($env) { // If $item is not marked safe then it will be escaped. return $this->escapeFilter($env, $item, 'html', NULL, TRUE); }, $value)); }, (array) $value)); } }
core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php +14 −0 Changes for core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php: 14 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -200,6 +200,20 @@ public function testSafeJoin() { ]; $result = $twig_extension->safeJoin($twig_environment, $items, '<br/>'); $this->assertEquals('<em>will be escaped</em><br/><em>will be markup</em><br/><strong>will be rendered</strong>', $result); // Ensure safe_join Twig filter supports Traversable variables. $items = new \ArrayObject([ '<em>will be escaped</em>', $markup, ['#markup' => '<strong>will be rendered</strong>'], ]); $result = $twig_extension->safeJoin($twig_environment, $items, ', '); $this->assertEquals('<em>will be escaped</em>, <em>will be markup</em>, <strong>will be rendered</strong>', $result); // Ensure safe_join Twig filter supports empty variables. $items = NULL; $result = $twig_extension->safeJoin($twig_environment, $items, '<br>'); $this->assertEmpty($result); } /** Loading