mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
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:
@@ -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
|
||||
é
|
||||
|
||||
Reference in New Issue
Block a user