diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index b368ced64..5ee3c514b 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -766,7 +766,7 @@ class View extends Object { } $name = str_replace('/', DS, $name); - if (strpos($name, DS) === false && strpos($name, '..') === false) { + if (strpos($name, DS) === false && $name[0] !== '.') { $name = $this->viewPath . DS . $subDir . Inflector::underscore($name); } elseif (strpos($name, DS) !== false) { if ($name{0} === DS || $name{1} === ':') { @@ -774,16 +774,13 @@ class View extends Object { return $name; } $name = trim($name, DS); + } else if ($name[0] === '.') { + $name = substr($name, 3); } else { $name = $this->viewPath . DS . $subDir . $name; } - } elseif (strpos($name, '..') !== false) { - $name = explode('/', $name); - $i = array_search('..', $name); - unset($name[$i - 1]); - unset($name[$i]); - $name = '..' . DS . implode(DS, $name); } + $paths = $this->_paths($this->plugin); foreach ($paths as $path) { diff --git a/cake/tests/cases/libs/view/helpers/rss.test.php b/cake/tests/cases/libs/view/helpers/rss.test.php index f823fed5d..be7fb0da7 100644 --- a/cake/tests/cases/libs/view/helpers/rss.test.php +++ b/cake/tests/cases/libs/view/helpers/rss.test.php @@ -216,7 +216,7 @@ class RssTest extends CakeTestCase { 'getViewFileName('/posts/index'); $this->assertEqual($result, $expected); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'posts' . DS .'index.ctp'; + $result = $View->getViewFileName('../posts/index'); + $this->assertEqual($result, $expected); + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS .'default.ctp'; $result = $View->getLayoutFileName(); $this->assertEqual($result, $expected); @@ -265,7 +269,7 @@ class ViewTest extends CakeTestCase { } /** * testMissingView method - * + * * @access public * @return void */ @@ -282,11 +286,11 @@ class ViewTest extends CakeTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean()); $this->assertPattern("/PagesController::/", $expected); - $this->assertPattern("/pages\/does_not_exist.ctp/", $expected); + $this->assertPattern("/pages(\/|\\\)does_not_exist.ctp/", $expected); } /** * testMissingLayout method - * + * * @access public * @return void */ @@ -302,12 +306,11 @@ class ViewTest extends CakeTestCase { $expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean()); $this->assertPattern("/Missing Layout/", $expected); - $this->assertPattern("/layouts\/whatever.ctp/", $expected); - + $this->assertPattern("/layouts(\/|\\\)whatever.ctp/", $expected); } /** * testViewVars method - * + * * @access public * @return void */ @@ -316,7 +319,7 @@ class ViewTest extends CakeTestCase { } /** * testUUIDGeneration method - * + * * @access public * @return void */ @@ -330,7 +333,7 @@ class ViewTest extends CakeTestCase { } /** * testAddInlineScripts method - * + * * @access public * @return void */ @@ -344,7 +347,7 @@ class ViewTest extends CakeTestCase { } /** * testElement method - * + * * @access public * @return void */ @@ -358,7 +361,7 @@ class ViewTest extends CakeTestCase { } /** * testElementCacheHelperNoCache method - * + * * @access public * @return void */ @@ -373,7 +376,7 @@ class ViewTest extends CakeTestCase { } /** * testElementCache method - * + * * @access public * @return void */ @@ -420,7 +423,7 @@ class ViewTest extends CakeTestCase { } /** * testLoadHelpers method - * + * * @access public * @return void */ @@ -441,7 +444,7 @@ class ViewTest extends CakeTestCase { } /** * testBeforeLayout method - * + * * @access public * @return void */ @@ -453,7 +456,7 @@ class ViewTest extends CakeTestCase { } /** * testAfterLayout method - * + * * @access public * @return void */ @@ -471,7 +474,7 @@ class ViewTest extends CakeTestCase { } /** * testRenderLoadHelper method - * + * * @access public * @return void */ @@ -503,7 +506,7 @@ class ViewTest extends CakeTestCase { } /** * testRender method - * + * * @access public * @return void */ @@ -540,18 +543,33 @@ class ViewTest extends CakeTestCase { $this->assertPattern("/
posts index<\/div>/", $result); $this->assertPattern("/
posts index<\/div>/", $result); } -/* - function testRenderElement() { - $View = new View($this->PostsController); - $element = 'element_name'; - $result = $View->renderElement($element); - $this->assertPattern('/Not Found/i', $result); +/** + * testGetViewFileName method + * + * @access public + * @return void + */ + function testViewFileName() { + $View = new TestView($this->PostsController); + + $result = $View->getViewFileName('index'); + $this->assertPattern('/posts(\/|\\\)index.ctp/', $result); + + $result = $View->getViewFileName('/pages/home'); + $this->assertPattern('/pages(\/|\\\)home.ctp/', $result); + + $result = $View->getViewFileName('../elements/test_element'); + $this->assertPattern('/elements(\/|\\\)test_element.ctp/', $result); + + $result = $View->getViewFileName('../themed/test_theme/posts/index'); + $this->assertPattern('/themed(\/|\\\)test_theme(\/|\\\)posts(\/|\\\)index.ctp/', $result); + + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'posts' . DS .'index.ctp'; + $result = $View->getViewFileName('../posts/index'); + $this->assertEqual($result, $expected); - $element = 'test_element'; - $result = $View->renderElement($element); - $this->assertPattern('/this is the test element/i', $result); } -*/ + function testRenderCache() { $view = 'test_view'; $View = new View($this->PostsController); @@ -578,7 +596,7 @@ class ViewTest extends CakeTestCase { } /** * testSet method - * + * * @access public * @return void */ @@ -606,7 +624,7 @@ class ViewTest extends CakeTestCase { } /** * testEntityReference method - * + * * @access public * @return void */ @@ -622,7 +640,7 @@ class ViewTest extends CakeTestCase { } /** * testBadExt method - * + * * @access public * @return void */ @@ -637,11 +655,11 @@ class ViewTest extends CakeTestCase { set_error_handler('simpleTestErrorHandler'); $this->assertPattern("/PostsController::<\/em>something\(\)<\/em>/", $result); - $this->assertPattern("/posts\/this_is_missing.whatever/", $result); + $this->assertPattern("/posts(\/|\\\)this_is_missing.whatever/", $result); } /** * tearDown method - * + * * @access public * @return void */