From 70981d05ca48cf7e7c4cb1d00d19a36bac2b77a4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 23 Dec 2011 23:56:48 -0500 Subject: [PATCH] Throw an exception when a view extends itself. --- lib/Cake/Test/Case/View/ViewTest.php | 11 +++++++++++ lib/Cake/Test/test_app/View/Posts/extend_self.ctp | 2 ++ lib/Cake/View/View.php | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 lib/Cake/Test/test_app/View/Posts/extend_self.ctp 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; }