Fixed usage of LimitIterator

This commit is contained in:
Andrey Grachov
2014-10-10 23:28:30 +03:00
committed by Fabien Potencier
parent 84df881b8b
commit f76e67f91d
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -697,7 +697,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese
} }
if ($start >= 0 && $length >= 0) { if ($start >= 0 && $length >= 0) {
return iterator_to_array(new LimitIterator($item, $start, $length), $preserveKeys); return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys);
} }
$item = iterator_to_array($item, $preserveKeys); $item = iterator_to_array($item, $preserveKeys);
@@ -19,6 +19,9 @@
{{ '1234'|slice(1) }} {{ '1234'|slice(1) }}
{{ '1234'[1:] }} {{ '1234'[1:] }}
{{ '1234'[:1] }} {{ '1234'[:1] }}
{{ arr|slice(3)|join('') }}
{{ arr[2:]|join('') }}
--DATA-- --DATA--
return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4))) return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4)))
--EXPECT-- --EXPECT--
@@ -40,3 +43,6 @@ bc
234 234
234 234
1 1
4
34