mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
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
This commit is contained in:
parent
513851d1c1
commit
59f84024e5
2 changed files with 27 additions and 1 deletions
|
@ -229,8 +229,10 @@ class CakeRequest implements ArrayAccess {
|
||||||
protected function _url() {
|
protected function _url() {
|
||||||
if (!empty($_SERVER['PATH_INFO'])) {
|
if (!empty($_SERVER['PATH_INFO'])) {
|
||||||
return $_SERVER['PATH_INFO'];
|
return $_SERVER['PATH_INFO'];
|
||||||
} elseif (isset($_SERVER['REQUEST_URI'])) {
|
} elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) {
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
$uri = $_SERVER['REQUEST_URI'];
|
||||||
|
} elseif (isset($_SERVER['REQUEST_URI'])) {
|
||||||
|
$uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL));
|
||||||
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
|
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
|
||||||
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
|
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
|
||||||
} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
|
} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
|
||||||
|
|
|
@ -1646,6 +1646,30 @@ class CakeRequestTest extends CakeTestCase {
|
||||||
'webroot' => '/',
|
'webroot' => '/',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'Apache - w/rewrite, document root set above top level cake dir, request root, absolute REQUEST_URI',
|
||||||
|
array(
|
||||||
|
'App' => array(
|
||||||
|
'base' => false,
|
||||||
|
'baseUrl' => false,
|
||||||
|
'dir' => 'app',
|
||||||
|
'webroot' => 'webroot'
|
||||||
|
),
|
||||||
|
'SERVER' => array(
|
||||||
|
'SERVER_NAME' => 'localhost',
|
||||||
|
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
|
||||||
|
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
|
||||||
|
'REQUEST_URI' => FULL_BASE_URL . '/site/posts/index',
|
||||||
|
'SCRIPT_NAME' => '/site/app/webroot/index.php',
|
||||||
|
'PHP_SELF' => '/site/app/webroot/index.php',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'url' => 'posts/index',
|
||||||
|
'base' => '/site',
|
||||||
|
'webroot' => '/site/',
|
||||||
|
),
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO',
|
'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO',
|
||||||
array(
|
array(
|
||||||
|
|
Loading…
Add table
Reference in a new issue