From: Kirill chEbba Chebunin Date: Thu, 31 Oct 2013 16:50:58 +0000 (+0400) Subject: Fix twig_first and twig_last filters for UTF8 multibyte strings X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=6003ae43b92cfa7e1ddec17262733355e0bf435a;p=konrad%2Ftwig.git Fix twig_first and twig_last filters for UTF8 multibyte strings --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 32d452d..afdeb65 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -692,7 +692,7 @@ function twig_first(Twig_Environment $env, $item) { $elements = twig_slice($env, $item, 0, 1, false); - return is_string($elements) ? $elements[0] : current($elements); + return is_string($elements) ? $elements : current($elements); } /** @@ -707,7 +707,7 @@ function twig_last(Twig_Environment $env, $item) { $elements = twig_slice($env, $item, -1, 1, false); - return is_string($elements) ? $elements[0] : current($elements); + return is_string($elements) ? $elements : current($elements); } /** diff --git a/test/Twig/Tests/Fixtures/filters/first.test b/test/Twig/Tests/Fixtures/filters/first.test index 853465b..90f4927 100644 --- a/test/Twig/Tests/Fixtures/filters/first.test +++ b/test/Twig/Tests/Fixtures/filters/first.test @@ -5,6 +5,7 @@ {{ {a: 1, b: 2, c: 3, d: 4}|first }} {{ '1234'|first }} {{ arr|first }} +{{ 'Ä€é'|first }} --DATA-- return array('arr' => new ArrayObject(array(1, 2, 3, 4))) --EXPECT-- @@ -12,3 +13,4 @@ return array('arr' => new ArrayObject(array(1, 2, 3, 4))) 1 1 1 +Ä diff --git a/test/Twig/Tests/Fixtures/filters/last.test b/test/Twig/Tests/Fixtures/filters/last.test index ca3ac0c..018fdad 100644 --- a/test/Twig/Tests/Fixtures/filters/last.test +++ b/test/Twig/Tests/Fixtures/filters/last.test @@ -5,6 +5,7 @@ {{ {a: 1, b: 2, c: 3, d: 4}|last }} {{ '1234'|last }} {{ arr|last }} +{{ 'Ä€é'|last }} --DATA-- return array('arr' => new ArrayObject(array(1, 2, 3, 4))) --EXPECT-- @@ -12,3 +13,4 @@ return array('arr' => new ArrayObject(array(1, 2, 3, 4))) 4 4 4 +é