diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index f8cbdc783..00ba9b2b1 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -332,15 +332,17 @@ class TextHelper extends AppHelper { * @access public */ function toList($list, $and = 'and') { - $r = ''; - $c = count($list) - 1; + $return = ''; + $count = count($list) - 1; + $counter = 0; foreach ($list as $i => $item) { - $r .= $item; - if ($c > 0 && $i < $c) { - $r .= ($i < $c - 1 ? ', ' : " {$and} "); + $return .= $item; + if ($count > 0 && $counter < $count) { + $return .= ($counter < $count - 1 ? ', ' : " {$and} "); } + $counter++; } - return $r; + return $return; } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 1901a7f52..a9c9ba63d 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -362,6 +362,9 @@ class TextHelperTest extends CakeTestCase { $result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y'); $this->assertEqual($result, 'Dusty, Lucky y Ned'); + + $result = $this->Text->toList(array( 1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'y'); + $this->assertEqual($result, 'Dusty, Lucky y Ned'); } } ?> \ No newline at end of file