Skip to content

Commit

Permalink
Fixed usage of LimitIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
grachov authored and fabpot committed Oct 10, 2014
1 parent 84df881 commit f76e67f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Twig/Extension/Core.php
Expand Up @@ -697,7 +697,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese
}

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);
Expand Down
6 changes: 6 additions & 0 deletions test/Twig/Tests/Fixtures/filters/slice.test
Expand Up @@ -19,6 +19,9 @@
{{ '1234'|slice(1) }}
{{ '1234'[1:] }}
{{ '1234'[:1] }}

{{ arr|slice(3)|join('') }}
{{ arr[2:]|join('') }}
--DATA--
return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4)))
--EXPECT--
Expand All @@ -40,3 +43,6 @@ bc
234
234
1

4
34

0 comments on commit f76e67f

Please sign in to comment.