Merge branch 'master' into 2.3

This commit is contained in:
mark_story 2012-08-03 22:45:56 -04:00
commit e59555a66f
12 changed files with 141 additions and 24 deletions

View file

@ -70,12 +70,15 @@ class AclShell extends AppShell {
$this->connection = $this->params['connection']; $this->connection = $this->params['connection'];
} }
if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) { $class = Configure::read('Acl.classname');
list($plugin, $class) = pluginSplit($class, true);
App::uses($class, $plugin . 'Controller/Component/Acl');
if (!in_array($class, array('DbAcl', 'DB_ACL')) && !is_subclass_of($class, 'DbAcl')) {
$out = "--------------------------------------------------\n"; $out = "--------------------------------------------------\n";
$out .= __d('cake_console', 'Error: Your current Cake configuration is set to an ACL implementation other than DB.') . "\n"; $out .= __d('cake_console', 'Error: Your current Cake configuration is set to an ACL implementation other than DB.') . "\n";
$out .= __d('cake_console', 'Please change your core config to reflect your decision to use DbAcl before attempting to use this script') . "\n"; $out .= __d('cake_console', 'Please change your core config to reflect your decision to use DbAcl before attempting to use this script') . "\n";
$out .= "--------------------------------------------------\n"; $out .= "--------------------------------------------------\n";
$out .= __d('cake_console', 'Current ACL Classname: %s', Configure::read('Acl.classname')) . "\n"; $out .= __d('cake_console', 'Current ACL Classname: %s', $class) . "\n";
$out .= "--------------------------------------------------\n"; $out .= "--------------------------------------------------\n";
$this->err($out); $this->err($out);
$this->_stop(); $this->_stop();

View file

@ -71,8 +71,8 @@ class TreeBehavior extends ModelBehavior {
if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) { if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) {
$data = $Model->getAssociated($settings['scope']); $data = $Model->getAssociated($settings['scope']);
$parent = $Model->{$settings['scope']}; $Parent = $Model->{$settings['scope']};
$settings['scope'] = $Model->alias . '.' . $data['foreignKey'] . ' = ' . $parent->alias . '.' . $parent->primaryKey; $settings['scope'] = $Model->escapeField($data['foreignKey']) . ' = ' . $Parent->escapeField();
$settings['recursive'] = 0; $settings['recursive'] = 0;
} }
$this->settings[$Model->alias] = $settings; $this->settings[$Model->alias] = $settings;
@ -126,8 +126,8 @@ class TreeBehavior extends ModelBehavior {
public function beforeDelete(Model $Model, $cascade = true) { public function beforeDelete(Model $Model, $cascade = true) {
extract($this->settings[$Model->alias]); extract($this->settings[$Model->alias]);
$data = $Model->find('first', array( $data = $Model->find('first', array(
'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id), 'conditions' => array($Model->escapeField($Model->primaryKey) => $Model->id),
'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right), 'fields' => array($Model->escapeField($left), $Model->escapeField($right)),
'recursive' => -1)); 'recursive' => -1));
if ($data) { if ($data) {
$this->_deletedRow = current($data); $this->_deletedRow = current($data);
@ -157,7 +157,7 @@ class TreeBehavior extends ModelBehavior {
if (is_string($scope)) { if (is_string($scope)) {
$scope = array($scope); $scope = array($scope);
} }
$scope[]["{$Model->alias}.{$left} BETWEEN ? AND ?"] = array($data[$left] + 1, $data[$right] - 1); $scope[][$Model->escapeField($left) . " BETWEEN ? AND ?"] = array($data[$left] + 1, $data[$right] - 1);
$Model->deleteAll($scope); $Model->deleteAll($scope);
} }
$this->_sync($Model, $diff, '-', '> ' . $data[$right]); $this->_sync($Model, $diff, '-', '> ' . $data[$right]);
@ -309,7 +309,7 @@ class TreeBehavior extends ModelBehavior {
$recursive = $overrideRecursive; $recursive = $overrideRecursive;
} }
if (!$order) { if (!$order) {
$order = $Model->alias . '.' . $left . ' asc'; $order = $Model->escapeField($left) . " asc";
} }
if ($direct) { if ($direct) {
$conditions = array($scope, $Model->escapeField($parent) => $id); $conditions = array($scope, $Model->escapeField($parent) => $id);
@ -374,7 +374,7 @@ class TreeBehavior extends ModelBehavior {
} else { } else {
array_unshift($valuePath, '%s' . $valuePath[0], '{n}.tree_prefix'); array_unshift($valuePath, '%s' . $valuePath[0], '{n}.tree_prefix');
} }
$order = $Model->alias . '.' . $left . ' asc'; $order = $Model->escapeField($left) . " asc";
$results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive')); $results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive'));
$stack = array(); $stack = array();
@ -934,13 +934,13 @@ class TreeBehavior extends ModelBehavior {
$db = ConnectionManager::getDataSource($Model->useDbConfig); $db = ConnectionManager::getDataSource($Model->useDbConfig);
if ($created) { if ($created) {
if (is_string($scope)) { if (is_string($scope)) {
$scope .= " AND {$Model->alias}.{$Model->primaryKey} <> "; $scope .= " AND " . $Model->escapeField() . " <> ";
$scope .= $db->value($Model->id, $Model->getColumnType($Model->primaryKey)); $scope .= $db->value($Model->id, $Model->getColumnType($Model->primaryKey));
} else { } else {
$scope['NOT'][$Model->alias . '.' . $Model->primaryKey] = $Model->id; $scope['NOT'][$Model->alias . '.' . $Model->primaryKey] = $Model->id;
} }
} }
$name = $Model->alias . '.' . $right; $name = $Model->escapeField($right);
list($edge) = array_values($Model->find('first', array( list($edge) = array_values($Model->find('first', array(
'conditions' => $scope, 'conditions' => $scope,
'fields' => $db->calculate($Model, 'max', array($name, $right)), 'fields' => $db->calculate($Model, 'max', array($name, $right)),
@ -960,7 +960,7 @@ class TreeBehavior extends ModelBehavior {
*/ */
protected function _getMin(Model $Model, $scope, $left, $recursive = -1) { protected function _getMin(Model $Model, $scope, $left, $recursive = -1) {
$db = ConnectionManager::getDataSource($Model->useDbConfig); $db = ConnectionManager::getDataSource($Model->useDbConfig);
$name = $Model->alias . '.' . $left; $name = $Model->escapeField($left);
list($edge) = array_values($Model->find('first', array( list($edge) = array_values($Model->find('first', array(
'conditions' => $scope, 'conditions' => $scope,
'fields' => $db->calculate($Model, 'min', array($name, $left)), 'fields' => $db->calculate($Model, 'min', array($name, $left)),
@ -992,15 +992,15 @@ class TreeBehavior extends ModelBehavior {
$field = $right; $field = $right;
} }
if (is_string($conditions)) { if (is_string($conditions)) {
$conditions = array("{$Model->alias}.{$field} {$conditions}"); $conditions = array($Model->escapeField($field) . " {$conditions}");
} }
if (($scope != '1 = 1' && $scope !== true) && $scope) { if (($scope != '1 = 1' && $scope !== true) && $scope) {
$conditions[] = $scope; $conditions[] = $scope;
} }
if ($created) { if ($created) {
$conditions['NOT'][$Model->alias . '.' . $Model->primaryKey] = $Model->id; $conditions['NOT'][$Model->escapeField()] = $Model->id;
} }
$Model->updateAll(array($Model->alias . '.' . $field => $Model->escapeField($field) . ' ' . $dir . ' ' . $shift), $conditions); $Model->updateAll(array($Model->escapeField($field) => $Model->escapeField($field) . ' ' . $dir . ' ' . $shift), $conditions);
$Model->recursive = $ModelRecursive; $Model->recursive = $ModelRecursive;
} }

View file

@ -137,6 +137,8 @@ class DatabaseSession implements CakeSessionHandlerInterface {
public function gc($expires = null) { public function gc($expires = null) {
if (!$expires) { if (!$expires) {
$expires = time(); $expires = time();
} else {
$expires = time() - $expires;
} }
return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false); return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false);
} }

View file

@ -2863,7 +2863,7 @@ class Model extends Object implements CakeEventListener {
$query['order'] = $field . ' ASC'; $query['order'] = $field . ' ASC';
$neighbors = $this->find('all', $query); $neighbors = $this->find('all', $query);
if (!array_key_exists('prev', $return)) { if (!array_key_exists('prev', $return)) {
$return['prev'] = $neighbors[0]; $return['prev'] = isset($neighbors[0]) ? $neighbors[0] : null;
} }
if (count($neighbors) === 2) { if (count($neighbors) === 2) {
$return['next'] = $neighbors[1]; $return['next'] = $neighbors[1];

View file

@ -143,9 +143,9 @@ class Dispatcher implements CakeEventListener {
$request = $beforeEvent->data['request']; $request = $beforeEvent->data['request'];
if ($beforeEvent->result instanceof CakeResponse) { if ($beforeEvent->result instanceof CakeResponse) {
if (isset($request->params['return'])) { if (isset($request->params['return'])) {
return $response->body(); return $beforeEvent->result->body();
} }
$response->send(); $beforeEvent->result->send();
return; return;
} }

View file

@ -3736,6 +3736,30 @@ class ModelReadTest extends BaseModelTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
/**
* Test find(neighbors) with missing fields so no neighbors are found.
*
* @return
*/
public function testFindNeighborsNoPrev() {
$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment');
$Article = new Article();
$result = $Article->find('neighbors', array(
'field' => 'Article.title',
'value' => 'Second Article',
'fields' => array('id'),
'conditions' => array(
'Article.title LIKE' => '%Article%'
),
'recursive' => 0,
));
$expected = array(
'prev' => null,
'next' => null
);
$this->assertEquals($expected, $result);
}
/** /**
* testFindCombinedRelations method * testFindCombinedRelations method
* *

View file

@ -717,4 +717,62 @@ class RssHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
} }
public function testElementNamespaceWithoutPrefix() {
$item = array(
'creator' => 'Alex',
);
$attributes = array(
'namespace' => 'http://link.com'
);
$result = $this->Rss->item($attributes, $item);
$expected = array(
'item' => array(
'xmlns' => 'http://link.com'
),
'creator' => array(
'xmlns' => 'http://link.com'
),
'Alex',
'/creator',
'/item'
);
$this->assertTags($result, $expected, true);
}
public function testElementNamespaceWithPrefix() {
$item = array(
'title' => 'Title',
'dc:creator' => 'Alex',
'xy:description' => 'descriptive words'
);
$attributes = array(
'namespace' => array(
'prefix' => 'dc',
'url' => 'http://link.com'
)
);
$result = $this->Rss->item($attributes, $item);
$expected = array(
'item' => array(
'xmlns:dc' => 'http://link.com'
),
'title' => array(
'xmlns:dc' => 'http://link.com'
),
'Title',
'/title',
'dc:creator' => array(
'xmlns:dc' => 'http://link.com'
),
'Alex',
'/dc:creator',
'description' => array(
'xmlns:dc' => 'http://link.com'
),
'descriptive words',
'/description',
'/item'
);
$this->assertTags($result, $expected, true);
}
} }

View file

@ -181,6 +181,16 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->autoLinkUrls($text); $result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
$expected = 'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
$text = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
$expected = 'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
$text = 'Text with a partial www.cakephp.org URL'; $text = 'Text with a partial www.cakephp.org URL';
$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL'; $expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
$result = $this->Text->autoLinkUrls($text); $result = $this->Text->autoLinkUrls($text);

View file

@ -246,7 +246,7 @@ abstract class ControllerTestCase extends CakeTestCase {
} }
$Dispatch->loadRoutes = $this->loadRoutes; $Dispatch->loadRoutes = $this->loadRoutes;
$Dispatch->parseParams(new CakeEvent('ControllerTestCase', $Dispatch, array('request' => $request))); $Dispatch->parseParams(new CakeEvent('ControllerTestCase', $Dispatch, array('request' => $request)));
if (!isset($request->params['controller'])) { if (!isset($request->params['controller']) && Router::currentRoute()) {
$this->headers = Router::currentRoute()->response->header(); $this->headers = Router::currentRoute()->response->header();
return; return;
} }

View file

@ -150,7 +150,17 @@ class CacheHelper extends AppHelper {
if ($cacheTime != '' && $cacheTime > 0) { if ($cacheTime != '' && $cacheTime > 0) {
$cached = $this->_parseOutput($out); $cached = $this->_parseOutput($out);
try {
$this->_writeFile($cached, $cacheTime, $useCallbacks); $this->_writeFile($cached, $cacheTime, $useCallbacks);
} catch (Exception $e) {
$message = __d(
'cake_dev',
'Unable to write view cache file: "%s" for "%s"',
$e->getMessage(),
$this->request->here
);
$this->log($message, 'error');
}
$out = $this->_stripTags($out); $out = $this->_stripTags($out);
} }
return $out; return $out;

View file

@ -256,6 +256,8 @@ class RssHelper extends AppHelper {
$attrib = $val; $attrib = $val;
$val = null; $val = null;
break; break;
default:
$attrib = $att;
} }
if (!is_null($val) && $escape) { if (!is_null($val) && $escape) {
$val = h($val); $val = h($val);
@ -312,7 +314,12 @@ class RssHelper extends AppHelper {
$xml = '<' . $name; $xml = '<' . $name;
if (!empty($namespace)) { if (!empty($namespace)) {
$xml .= ' xmlns:"' . $namespace . '"'; $xml .= ' xmlns';
if (is_array($namespace)) {
$xml .= ':' . $namespace['prefix'];
$namespace = $namespace['url'];
}
$xml .= '="' . $namespace . '"';
} }
$bareName = $name; $bareName = $name;
if (strpos($name, ':') !== false) { if (strpos($name, ':') !== false) {
@ -329,9 +336,11 @@ class RssHelper extends AppHelper {
$xml .= '>' . $content . '</' . $name . '>'; $xml .= '>' . $content . '</' . $name . '>';
$elem = Xml::build($xml, array('return' => 'domdocument')); $elem = Xml::build($xml, array('return' => 'domdocument'));
$nodes = $elem->getElementsByTagName($bareName); $nodes = $elem->getElementsByTagName($bareName);
if ($attrib) {
foreach ($attrib as $key => $value) { foreach ($attrib as $key => $value) {
$nodes->item(0)->setAttribute($key, $value); $nodes->item(0)->setAttribute($key, $value);
} }
}
foreach ($children as $k => $child) { foreach ($children as $k => $child) {
$child = $elem->createElement($name, $child); $child = $elem->createElement($name, $child);
$nodes->item(0)->appendChild($child); $nodes->item(0)->appendChild($child);

View file

@ -101,8 +101,9 @@ class TextHelper extends AppHelper {
$this->_placeholders = array(); $this->_placeholders = array();
$options += array('escape' => true); $options += array('escape' => true);
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[^\s<>()]+\.[a-z]+(?:\/[^\s]+)?)#i';
$text = preg_replace_callback( $text = preg_replace_callback(
'#(?<!href="|src="|">)((?:https?|ftp|nntp)://[^\s<>()]+)#i', $pattern,
array(&$this, '_insertPlaceHolder'), array(&$this, '_insertPlaceHolder'),
$text $text
); );