Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 22352a02270f673e4884a809c04a0db220cbabd5 1 parent d4fd1b3
Mark Story authored December 02, 2011
4  lib/Cake/Network/CakeRequest.php
@@ -278,10 +278,10 @@ protected function _base() {
278 278
 		$docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot);
279 279
 
280 280
 		if (!empty($base) || !$docRootContainsWebroot) {
281  
-			if (strpos($this->webroot, $dir) === false) {
  281
+			if (strpos($this->webroot, '/' . $dir . '/') === false) {
282 282
 				$this->webroot .= $dir . '/' ;
283 283
 			}
284  
-			if (strpos($this->webroot, $webroot) === false) {
  284
+			if (strpos($this->webroot, '/' . $webroot . '/') === false) {
285 285
 				$this->webroot .= $webroot . '/';
286 286
 			}
287 287
 		}
23  lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -1042,6 +1042,29 @@ public function testBaseUrlNoRewriteTopLevelIndex() {
1042 1042
 	}
1043 1043
 
1044 1044
 /**
  1045
+ * Check that a sub-directory containing app|webroot doesn't get mishandled when re-writing is off.
  1046
+ *
  1047
+ * @return void
  1048
+ */
  1049
+	public function testBaseUrlWithAppAndWebrootInDirname() {
  1050
+		Configure::write('App.baseUrl', '/approval/index.php');
  1051
+		$_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
  1052
+		$_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/approval/index.php';
  1053
+
  1054
+		$request = new CakeRequest();
  1055
+		$this->assertEquals('/approval/index.php', $request->base);
  1056
+		$this->assertEquals('/approval/app/webroot/', $request->webroot);
  1057
+
  1058
+		Configure::write('App.baseUrl', '/webrootable/index.php');
  1059
+		$_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
  1060
+		$_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/webrootable/index.php';
  1061
+
  1062
+		$request = new CakeRequest();
  1063
+		$this->assertEquals('/webrootable/index.php', $request->base);
  1064
+		$this->assertEquals('/webrootable/app/webroot/', $request->webroot);
  1065
+	}
  1066
+
  1067
+/**
1045 1068
  * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
1046 1069
  *
1047 1070
  * @return void

0 notes on commit 22352a0

Please sign in to comment.
Something went wrong with that request. Please try again.