diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 7cdcdb5bd..fc148e1e9 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1158,6 +1158,18 @@ TEXT; $this->View->render('extend_self'); } +/** + * Make sure that extending in a loop causes an exception + * + * @expectedException LogicException + * @return void + */ + public function testExtendLoop() { + $this->View->layout = false; + $this->View->render('extend_loop'); + } + + /** * Test extend() in an element and a view. * diff --git a/lib/Cake/Test/test_app/View/Posts/extend_loop.ctp b/lib/Cake/Test/test_app/View/Posts/extend_loop.ctp new file mode 100644 index 000000000..f7a07aedf --- /dev/null +++ b/lib/Cake/Test/test_app/View/Posts/extend_loop.ctp @@ -0,0 +1,2 @@ +extend('extend_loop_inner'); ?> +Outer element. diff --git a/lib/Cake/Test/test_app/View/Posts/extend_loop_inner.ctp b/lib/Cake/Test/test_app/View/Posts/extend_loop_inner.ctp new file mode 100644 index 000000000..efde05804 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Posts/extend_loop_inner.ctp @@ -0,0 +1,2 @@ +extend('extend_loop'); ?> +Inner loop element. diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index ba329cdc1..69ba7b676 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -619,6 +619,7 @@ class View extends Object { * * @param string $name The view or element to 'extend' the current one with. * @return void + * @throws LogicException when you extend a view with itself or make extend loops. */ public function extend($name) { switch ($this->_currentType) { @@ -636,6 +637,9 @@ class View extends Object { if ($parent == $this->_current) { throw new LogicException(__d('cake_dev', 'You cannot have views extend themselves.')); } + if (isset($this->_parents[$parent]) && $this->_parents[$parent] == $this->_current) { + throw new LogicException(__d('cake_dev', 'You cannot have views extend in a loop.')); + } $this->_parents[$this->_current] = $parent; }