bug #3075 [1.x] Patch split filter (adriansuter)

This PR was squashed before being merged into the 1.x branch (closes #3075).

Discussion
----------

[1.x] Patch split filter

This PR addresses #3072 vor Twig 1.x.

Commits
-------

4c4df962 [1.x] Patch split filter
This commit is contained in:
Fabien Potencier
2019-06-25 07:35:04 +02:00
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -790,7 +790,7 @@ function twig_join_filter($value, $glue = '', $and = null)
*/
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
{
if (!empty($delimiter)) {
if (strlen($delimiter)) {
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
}
+3 -1
View File
@@ -8,6 +8,7 @@
{{ baz|split('', 1)|join('-') }}
{{ baz|split('', 2)|join('-') }}
{{ foo|split(',', -2)|join('-') }}
{{ "hello0world"|split('0')|join('-') }}
--DATA--
return ['foo' => "one,two,three,four,five", 'baz' => '12345',]
--EXPECT--
@@ -17,4 +18,5 @@ one-two-three,four,five
1-2-3-4-5
1-2-3-4-5
12-34-5
one-two-three
one-two-three
hello-world