From 3ecce19732c06f309e5dbdde7d4f8456cab20bef Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 19 Dec 2013 15:58:08 +0100 Subject: [PATCH] Correct tokenize for empty strings. --- lib/Cake/Test/Case/Utility/StringTest.php | 4 ++++ lib/Cake/Utility/String.php | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/StringTest.php b/lib/Cake/Test/Case/Utility/StringTest.php index ac047868f..abcc9e1a2 100644 --- a/lib/Cake/Test/Case/Utility/StringTest.php +++ b/lib/Cake/Test/Case/Utility/StringTest.php @@ -303,6 +303,10 @@ class StringTest extends CakeTestCase { $result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"'); $expected = array('tagA', '"single tag"', 'tagB'); $this->assertEquals($expected, $result); + + $result = String::tokenize(''); + $expected = array(); + $this->assertEquals($expected, $result); } public function testReplaceWithQuestionMarkInString() { diff --git a/lib/Cake/Utility/String.php b/lib/Cake/Utility/String.php index 53555cd37..8e8e7195b 100644 --- a/lib/Cake/Utility/String.php +++ b/lib/Cake/Utility/String.php @@ -99,17 +99,17 @@ class String { /** * Tokenizes a string using $separator, ignoring any instance of $separator that appears between - * $leftBound and $rightBound + * $leftBound and $rightBound. * - * @param string $data The data to tokenize + * @param string $data The data to tokenize. * @param string $separator The token to split the data on. * @param string $leftBound The left boundary to ignore separators in. * @param string $rightBound The right boundary to ignore separators in. * @return array Array of tokens in $data. */ public static function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') { - if (empty($data) || is_array($data)) { - return $data; + if (empty($data)) { + return array(); } $depth = 0;