Skip to content
This repository
Browse code

Throw an exception when a view extends itself.

  • Loading branch information...
commit 70981d05ca48cf7e7c4cb1d00d19a36bac2b77a4 1 parent 047e93e
Mark Story authored December 23, 2011 markstory committed December 27, 2011
11  lib/Cake/Test/Case/View/ViewTest.php
@@ -1148,6 +1148,17 @@ public function testExtendNested() {
1148 1148
 	}
1149 1149
 
1150 1150
 /**
  1151
+ * Make sure that extending the current view with itself causes an exception
  1152
+ *
  1153
+ * @expectedException LogicException
  1154
+ * @return void
  1155
+ */
  1156
+	public function testExtendSelf() {
  1157
+		$this->View->layout = false;
  1158
+		$this->View->render('extend_self');
  1159
+	}
  1160
+
  1161
+/**
1151 1162
  * Test extend() in an element and a view.
1152 1163
  *
1153 1164
  * @return void
2  lib/Cake/Test/test_app/View/Posts/extend_self.ctp
... ...
@@ -0,0 +1,2 @@
  1
+<?php $this->extend('extend_self'); ?>
  2
+To infinifty and beyond.
3  lib/Cake/View/View.php
@@ -633,6 +633,9 @@ public function extend($name) {
633 633
 			break;
634 634
 		
635 635
 		}
  636
+		if ($parent == $this->_current) {
  637
+			throw new LogicException(__d('cake_dev', 'You cannot have views extend themselves.'));
  638
+		}
636 639
 		$this->_parents[$this->_current] = $parent;
637 640
 	}
638 641
 

0 notes on commit 70981d0

Please sign in to comment.
Something went wrong with that request. Please try again.