diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 9249480a5..6a4daa12f 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -336,7 +336,11 @@ class TextHelper extends AppHelper { * @access public */ function toList($list, $and = 'and', $separator = ', ') { - return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list); + if (count($list) > 1) { + return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list); + } else { + return array_pop($list); + } } } ?> \ 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 39f7bed3f..00e880539 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -355,6 +355,12 @@ class TextHelperTest extends CakeTestCase { * @return void */ function testListGeneration() { + $result = $this->Text->toList(array()); + $this->assertEqual($result, ''); + + $result = $this->Text->toList(array('One')); + $this->assertEqual($result, 'One'); + $result = $this->Text->toList(array('Larry', 'Curly', 'Moe')); $this->assertEqual($result, 'Larry, Curly and Moe');