From 22352a02270f673e4884a809c04a0db220cbabd5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 2 Dec 2011 23:39:33 -0500 Subject: [PATCH] Fix missing directory in dispatcher with rewrite off. When re-writing is disabled, and the deployment directory contains either 'app' or 'webroot' the computed path was incorrect. Fixes #2330 --- lib/Cake/Network/CakeRequest.php | 4 ++-- .../Test/Case/Network/CakeRequestTest.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 75689fa87..c2c498d7b 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -278,10 +278,10 @@ class CakeRequest implements ArrayAccess { $docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot); if (!empty($base) || !$docRootContainsWebroot) { - if (strpos($this->webroot, $dir) === false) { + if (strpos($this->webroot, '/' . $dir . '/') === false) { $this->webroot .= $dir . '/' ; } - if (strpos($this->webroot, $webroot) === false) { + if (strpos($this->webroot, '/' . $webroot . '/') === false) { $this->webroot .= $webroot . '/'; } } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 95bf2177f..1ccd441b2 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1041,6 +1041,29 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('/app/webroot/', $request->webroot); } +/** + * Check that a sub-directory containing app|webroot doesn't get mishandled when re-writing is off. + * + * @return void + */ + public function testBaseUrlWithAppAndWebrootInDirname() { + Configure::write('App.baseUrl', '/approval/index.php'); + $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/'; + $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/approval/index.php'; + + $request = new CakeRequest(); + $this->assertEquals('/approval/index.php', $request->base); + $this->assertEquals('/approval/app/webroot/', $request->webroot); + + Configure::write('App.baseUrl', '/webrootable/index.php'); + $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/'; + $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/webrootable/index.php'; + + $request = new CakeRequest(); + $this->assertEquals('/webrootable/index.php', $request->base); + $this->assertEquals('/webrootable/app/webroot/', $request->webroot); + } + /** * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts. *