diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 8f7c090cb..34edf294d 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1449,56 +1449,10 @@ class DboSource extends DataSource { if (empty($alias)) { $alias = $model->alias; } - - if (!is_array($fields)) { - if (!empty($fields)) { - $depth = 0; - $offset = 0; - $buffer = ''; - $results = array(); - $length = strlen($fields); - - while ($offset <= $length) { - $tmpOffset = -1; - $offsets = array(strpos($fields, ',', $offset), strpos($fields, '(', $offset), strpos($fields, ')', $offset)); - for ($i = 0; $i < 3; $i++) { - if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset == -1)) { - $tmpOffset = $offsets[$i]; - } - } - if ($tmpOffset !== -1) { - $buffer .= substr($fields, $offset, ($tmpOffset - $offset)); - if ($fields{$tmpOffset} == ',' && $depth == 0) { - $results[] = $buffer; - $buffer = ''; - } else { - $buffer .= $fields{$tmpOffset}; - } - if ($fields{$tmpOffset} == '(') { - $depth++; - } - if ($fields{$tmpOffset} == ')') { - $depth--; - } - $offset = ++$tmpOffset; - } else { - $results[] = $buffer . substr($fields, $offset); - $offset = $length + 1; - } - } - if (empty($results) && !empty($buffer)) { - $results[] = $buffer; - } - - if (!empty($results)) { - $fields = array_map('trim', $results); - } else { - $fields = array(); - } - } - } if (empty($fields)) { $fields = array_keys($model->schema()); + } elseif (!is_array($fields)) { + $fields = String::tokenize($fields); } else { $fields = array_filter($fields); } diff --git a/cake/libs/string.php b/cake/libs/string.php index d65134dd2..3293852be 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -370,6 +370,66 @@ class String extends Object { } return $_this->ascii($upperCase); } +/** + * Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound + * and $rightBound + * + * @param string $data The data to tokenize + * @param string $separator The token to split the data on + * @return string + * @access public + * @static + */ + function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') { + if(empty($data) || is_array($data)) { + return $data; + } + + $depth = 0; + $offset = 0; + $buffer = ''; + $results = array(); + $length = strlen($data); + + while ($offset <= $length) { + $tmpOffset = -1; + $offsets = array(strpos($data, $separator, $offset), strpos($data, $leftBound, $offset), strpos($data, $rightBound, $offset)); + for ($i = 0; $i < 3; $i++) { + if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset == -1)) { + $tmpOffset = $offsets[$i]; + } + } + if ($tmpOffset !== -1) { + $buffer .= substr($data, $offset, ($tmpOffset - $offset)); + if ($data{$tmpOffset} == $separator && $depth == 0) { + $results[] = $buffer; + $buffer = ''; + } else { + $buffer .= $data{$tmpOffset}; + } + if ($data{$tmpOffset} == $leftBound) { + $depth++; + } + if ($data{$tmpOffset} == $rightBound) { + $depth--; + } + $offset = ++$tmpOffset; + } else { + $results[] = $buffer . substr($data, $offset); + $offset = $length + 1; + } + } + if (empty($results) && !empty($buffer)) { + $results[] = $buffer; + } + + if (!empty($results)) { + $data = array_map('trim', $results); + } else { + $data = array(); + } + return $data; + } /** * Return the Code points range for Unicode characters * diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index c8cd6a08d..962279671 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -43,7 +43,7 @@ class SessionComponentTest extends CakeTestCase { function testSessionAutoStart() { $this->Session->startup(new SessionTestController()); - $this->assertTrue(isset($_SESSION) && empty($_SESSION)); + $this->assertTrue(isset($_SESSION)); } function testSessionWriting() {