Skip to content

Commit

Permalink
Fix incorrect handling of url in path
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed May 20, 2016
1 parent 25dee75 commit 6a31a7b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Network/Request.php
Expand Up @@ -336,11 +336,10 @@ protected static function _url($config)
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) {
$uri = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$qPosition = strpos($_SERVER['REQUEST_URI'], '?');
if ($qPosition !== false && strpos($_SERVER['REQUEST_URI'], '://') > $qPosition) {
$uri = $_SERVER['REQUEST_URI'];
} else {
$uri = substr($_SERVER['REQUEST_URI'], strlen(Configure::read('App.fullBaseUrl')));
$uri = $_SERVER['REQUEST_URI'];
$fullBaseUrl = Configure::read('App.fullBaseUrl');
if (strpos($uri, $fullBaseUrl) === 0) {
$uri = substr($_SERVER['REQUEST_URI'], strlen($fullBaseUrl));
}
} elseif (isset($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME'])) {
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -177,6 +177,20 @@ public function testQueryStringAndNamedParams()
$this->assertEquals('other/path', $request->url);
}

/**
* Test that URL in path is handled correctly.
*/
public function testUrlInPath()
{
$_SERVER['REQUEST_URI'] = '/jump/http://cakephp.org';
$request = Request::createFromGlobals();
$this->assertEquals('jump/http://cakephp.org', $request->url);

$_SERVER['REQUEST_URI'] = Configure::read('App.fullBaseUrl') . '/jump/http://cakephp.org';
$request = Request::createFromGlobals();
$this->assertEquals('jump/http://cakephp.org', $request->url);
}

/**
* Test addParams() method
*
Expand Down

0 comments on commit 6a31a7b

Please sign in to comment.