bug #1258 Fix twig_first and twig_last filters for UTF8 multibyte strings (chEbba)

This PR was squashed before being merged into the master branch (closes #1258).

Discussion
----------

Fix twig_first and twig_last filters for UTF8 multibyte strings

After string is sliced we already have the right result with a first/last letter for UTF8 string.

Commits
-------

6003ae4 Fix twig_first and twig_last filters for UTF8 multibyte strings
This commit is contained in:
Fabien Potencier
2013-11-03 10:11:57 +01:00
3 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -693,7 +693,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);
}
/**
@@ -708,7 +708,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
é