From b44dba5c7c1d13f514d55cadcdc4fbc38ad4e652 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 2 Jan 2012 15:10:19 +0100 Subject: [PATCH] fixed the join filter when several items have the same key --- lib/Twig/Extension/Core.php | 2 +- test/Twig/Tests/integrationTest.php | 35 +++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 8ca4c8e..f5d2acd 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -489,7 +489,7 @@ function twig_array_merge($arr1, $arr2) function twig_join_filter($value, $glue = '') { if ($value instanceof Traversable) { - $value = iterator_to_array($value); + $value = iterator_to_array($value, false); } return implode($glue, (array) $value); diff --git a/test/Twig/Tests/integrationTest.php b/test/Twig/Tests/integrationTest.php index 6d36d6d..8f1d370 100644 --- a/test/Twig/Tests/integrationTest.php +++ b/test/Twig/Tests/integrationTest.php @@ -114,20 +114,18 @@ function test_foo($value = 'foo') return $value; } -class Foo implements IteratorAggregate +class Foo implements Iterator { const BAR_NAME = 'bar'; + public $position = 0; + public $array = array(1, 2); + public function bar($param1 = null, $param2 = null) { return 'bar'.($param1 ? '_'.$param1 : '').($param2 ? '-'.$param2 : ''); } - public function getIterator() - { - return new ArrayObject(array(1, 2)); - } - public function getFoo() { return 'foo'; @@ -157,6 +155,31 @@ class Foo implements IteratorAggregate { return strtolower($value); } + + public function rewind() + { + $this->position = 0; + } + + public function current() + { + return $this->array[$this->position]; + } + + public function key() + { + return 'a'; + } + + public function next() + { + ++$this->position; + } + + public function valid() + { + return isset($this->array[$this->position]); + } } class TestTokenParser_☃ extends Twig_TokenParser -- 1.7.2.5