diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 87799cfbc..7cdcdb5bd 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1147,6 +1147,17 @@ TEXT; $this->assertEquals($expected, $content); } +/** + * Make sure that extending the current view with itself causes an exception + * + * @expectedException LogicException + * @return void + */ + public function testExtendSelf() { + $this->View->layout = false; + $this->View->render('extend_self'); + } + /** * Test extend() in an element and a view. * diff --git a/lib/Cake/Test/test_app/View/Posts/extend_self.ctp b/lib/Cake/Test/test_app/View/Posts/extend_self.ctp new file mode 100644 index 000000000..3515819bc --- /dev/null +++ b/lib/Cake/Test/test_app/View/Posts/extend_self.ctp @@ -0,0 +1,2 @@ +extend('extend_self'); ?> +To infinifty and beyond. diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index a5b096505..ba329cdc1 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -633,6 +633,9 @@ class View extends Object { break; } + if ($parent == $this->_current) { + throw new LogicException(__d('cake_dev', 'You cannot have views extend themselves.')); + } $this->_parents[$this->_current] = $parent; }