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. *