From aea075b3a84fc1818b5e41f0cfc8e85dccf77f63 Mon Sep 17 00:00:00 2001 From: Thomas Pomfret Date: Thu, 26 Feb 2015 15:25:06 -0500 Subject: [PATCH] Updates slice so that it still accepts a SimpleXMLElement --- lib/Twig/Extension/Core.php | 2 +- test/Twig/Tests/Fixtures/filters/slice.test | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 92feea5e7..346006d32 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -707,7 +707,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese $item = $item->getIterator(); } - if ($start >= 0 && $length >= 0) { + if ($start >= 0 && $length >= 0 && $item instanceof Iterator) { try { return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys); } catch (OutOfBoundsException $exception) { diff --git a/test/Twig/Tests/Fixtures/filters/slice.test b/test/Twig/Tests/Fixtures/filters/slice.test index c10fe9355..b49b89fe5 100644 --- a/test/Twig/Tests/Fixtures/filters/slice.test +++ b/test/Twig/Tests/Fixtures/filters/slice.test @@ -24,8 +24,9 @@ {{ arr|slice(3)|join('') }} {{ arr[2:]|join('') }} +{{ xml|slice(1)|join('')}} --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)), 'xml' => new SimpleXMLElement('12')) --EXPECT-- 23 23 @@ -49,4 +50,5 @@ bc 1 4 -34 \ No newline at end of file +34 +2