mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #2506 from dereuromark/2.5-string
Correct tokenize for empty strings.
This commit is contained in:
commit
60d2ece035
2 changed files with 8 additions and 4 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 mixed Array of tokens in $data or original input if empty.
|
||||
*/
|
||||
public static function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') {
|
||||
if (empty($data) || is_array($data)) {
|
||||
return $data;
|
||||
if (empty($data)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$depth = 0;
|
||||
|
|
Loading…
Reference in a new issue