Permalink
Browse files

Correct tokenize for empty strings.

  • Loading branch information...
1 parent dc52f0b commit 3ecce19732c06f309e5dbdde7d4f8456cab20bef @dereuromark dereuromark committed Dec 19, 2013
Showing with 8 additions and 4 deletions.
  1. +4 −0 lib/Cake/Test/Case/Utility/StringTest.php
  2. +4 −4 lib/Cake/Utility/String.php
@@ -303,6 +303,10 @@ public function testTokenize() {
$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() {
@@ -99,17 +99,17 @@ public static function uuid() {
/**
* 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;

0 comments on commit 3ecce19

Please sign in to comment.