Skip to content
This repository
Browse code

Handle REQUEST_URI with domain names properly.

Don't depend on parse_url() as it fails with corrupted urls.  Instead
use FULL_BASE_URL to prepare an absolute path.

Fixes #3270
  • Loading branch information...
commit 59f84024e558169b2a79b395779971fce7fa7055 1 parent 513851d
Mark Story authored October 14, 2012
4  lib/Cake/Network/CakeRequest.php
@@ -229,8 +229,10 @@ protected function _processGet() {
229 229
 	protected function _url() {
230 230
 		if (!empty($_SERVER['PATH_INFO'])) {
231 231
 			return $_SERVER['PATH_INFO'];
232  
-		} elseif (isset($_SERVER['REQUEST_URI'])) {
  232
+		} elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) {
233 233
 			$uri = $_SERVER['REQUEST_URI'];
  234
+		} elseif (isset($_SERVER['REQUEST_URI'])) {
  235
+			$uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL));
234 236
 		} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
235 237
 			$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
236 238
 		} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
24  lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -1647,6 +1647,30 @@ public static function environmentGenerator() {
1647 1647
 				),
1648 1648
 			),
1649 1649
 			array(
  1650
+				'Apache - w/rewrite, document root set above top level cake dir, request root, absolute REQUEST_URI',
  1651
+				array(
  1652
+					'App' => array(
  1653
+						'base' => false,
  1654
+						'baseUrl' => false,
  1655
+						'dir' => 'app',
  1656
+						'webroot' => 'webroot'
  1657
+					),
  1658
+					'SERVER' => array(
  1659
+						'SERVER_NAME' => 'localhost',
  1660
+						'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
  1661
+						'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
  1662
+						'REQUEST_URI' => FULL_BASE_URL . '/site/posts/index',
  1663
+						'SCRIPT_NAME' => '/site/app/webroot/index.php',
  1664
+						'PHP_SELF' => '/site/app/webroot/index.php',
  1665
+					),
  1666
+				),
  1667
+				array(
  1668
+					'url' => 'posts/index',
  1669
+					'base' => '/site',
  1670
+					'webroot' => '/site/',
  1671
+				),
  1672
+			),
  1673
+			array(
1650 1674
 				'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO',
1651 1675
 				array(
1652 1676
 					'App' => array(

0 notes on commit 59f8402

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