Fix twig_first and twig_last filters for UTF8 multibyte strings

This commit is contained in:
Kirill chEbba Chebunin
2013-10-31 20:50:58 +04:00
committed by Fabien Potencier
parent 726a40a1b4
commit 6003ae43b9
3 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -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);
}
/**
@@ -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
Ä
@@ -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
é