Skip to content

Commit

Permalink
Fix illegal offset caused by TranslateBehavior.
Browse files Browse the repository at this point in the history
If you load TranslateBehavior at runtime in a disabled state, the enabled
flag would be interpreted as an association and cause errors.

Fixes #2443
  • Loading branch information
markstory committed Jan 7, 2012
1 parent 8792441 commit beced84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Cake/Model/BehaviorCollection.php
Expand Up @@ -106,6 +106,9 @@ public function load($behavior, $config = array()) {
$alias = $behavior;
$behavior = $config['className'];
}
$configDisabled = isset($config['enabled']) && $config['enabled'] === false;
unset($config['enabled'], $config['className']);

list($plugin, $name) = pluginSplit($behavior, true);
if (!isset($alias)) {
$alias = $name;
Expand Down Expand Up @@ -165,7 +168,6 @@ public function load($behavior, $config = array()) {
}
}

$configDisabled = isset($config['enabled']) && $config['enabled'] === false;
if (!in_array($alias, $this->_enabled) && !$configDisabled) {
$this->enable($alias);
} elseif ($configDisabled) {
Expand Down
15 changes: 14 additions & 1 deletion lib/Cake/Test/Case/Model/BehaviorCollectionTest.php
Expand Up @@ -419,9 +419,22 @@ class BehaviorCollectionTest extends CakeTestCase {
*/
public $fixtures = array(
'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment',
'core.attachment', 'core.tag', 'core.articles_tag'
'core.attachment', 'core.tag', 'core.articles_tag', 'core.translate'
);

/**
* Test load() with enabled => false
*
*/
public function testLoadDisabled() {
$Apple = new Apple();
$this->assertSame($Apple->Behaviors->attached(), array());

$Apple->Behaviors->load('Translate', array('enabled' => false));
$this->assertTrue($Apple->Behaviors->attached('Translate'));
$this->assertFalse($Apple->Behaviors->enabled('Translate'));
}

/**
* Tests loading aliased behaviors
*/
Expand Down

0 comments on commit beced84

Please sign in to comment.