Permalink
Browse files

Fix extending in loops.

  • Loading branch information...
1 parent 70981d0 commit 69b1c33f1f29799445c0f5e83a21ae2d213eb627 @markstory markstory committed Dec 24, 2011
@@ -1158,6 +1158,18 @@ public function testExtendSelf() {
$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.
*
@@ -0,0 +1,2 @@
+<?php $this->extend('extend_loop_inner'); ?>
+Outer element.
@@ -0,0 +1,2 @@
+<?php $this->extend('extend_loop'); ?>
+Inner loop element.
View
@@ -619,6 +619,7 @@ public function end() {
*
* @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 @@ public function extend($name) {
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;
}

0 comments on commit 69b1c33

Please sign in to comment.