Skip to content

Commit

Permalink
Adding return statement, preventing infinite loops when no default fi…
Browse files Browse the repository at this point in the history
…elds are bound, and unbindTranslation() is called with no fields. Fixes #307
  • Loading branch information
markstory committed Feb 12, 2010
1 parent 0611f1b commit 0ce14ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cake/libs/model/behaviors/translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ function bindTranslation(&$model, $fields, $reset = true) {
* @return bool
*/
function unbindTranslation(&$model, $fields = null) {
if (empty($fields) && empty($this->settings[$model->alias])) {
return false;
}
if (empty($fields)) {
return $this->unbindTranslation($model, $this->settings[$model->alias]);
}
Expand Down
18 changes: 18 additions & 0 deletions cake/tests/cases/libs/model/behaviors/translate.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,5 +877,23 @@ function testTranslateTableWithPrefix() {
));
$this->assertEqual($result, $expected);
}

/**
* Test infinite loops not occuring with unbindTranslation()
*
* @return void
*/
function testUnbindTranslationInfinteLoop() {
$this->loadFixtures('Translate', 'TranslatedItem');

$TestModel =& new TranslatedItem();
$TestModel->Behaviors->detach('Translate');
$TestModel->actsAs = array();
$TestModel->Behaviors->attach('Translate');
$TestModel->bindTranslation(array('title', 'content'), true);
$result = $TestModel->unbindTranslation();

$this->assertFalse($result);
}
}
?>

0 comments on commit 0ce14ce

Please sign in to comment.