Skip to content

Commit

Permalink
Fix twig_first and twig_last filters for UTF8 multibyte strings
Browse files Browse the repository at this point in the history
  • Loading branch information
chEbba authored and fabpot committed Nov 3, 2013
1 parent 726a40a commit 6003ae4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Twig/Extension/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/Twig/Tests/Fixtures/filters/first.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
{{ {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--
1
1
1
1
Ä
2 changes: 2 additions & 0 deletions test/Twig/Tests/Fixtures/filters/last.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
{{ {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--
4
4
4
4
é

0 comments on commit 6003ae4

Please sign in to comment.