Merge pull request #2694 from bar/patch-3

Correctly remove routing url from query string.
This commit is contained in:
José Lorenzo Rodríguez 2014-01-22 05:15:03 -08:00
commit ddf046a246
2 changed files with 47 additions and 3 deletions

View file

@ -207,7 +207,7 @@ class CakeRequest implements ArrayAccess {
$query = $_GET;
}
unset($query['/' . str_replace('.', '_', urldecode($this->url))]);
unset($query[$this->base . '/' . str_replace('.', '_', urldecode($this->url))]);
if (strpos($this->url, '?') !== false) {
list(, $querystr) = explode('?', $this->url);
parse_str($querystr, $queryArgs);

View file

@ -1484,10 +1484,18 @@ class CakeRequestTest extends CakeTestCase {
public function testGetParamsWithDot() {
$_GET = array();
$_GET['/posts/index/add_add'] = '';
$_SERVER['PHP_SELF'] = '/app/webroot/index.php';
$_SERVER['REQUEST_URI'] = '/posts/index/add.add';
$request = new CakeRequest();
$this->assertEquals('', $request->base);
$this->assertEquals(array(), $request->query);
$_GET = array();
$_GET['/cake_dev/posts/index/add_add'] = '';
$_SERVER['PHP_SELF'] = '/cake_dev/app/webroot/index.php';
$_SERVER['REQUEST_URI'] = '/cake_dev/posts/index/add.add';
$request = new CakeRequest();
$this->assertEquals('/cake_dev', $request->base);
$this->assertEquals(array(), $request->query);
}
@ -1499,10 +1507,18 @@ class CakeRequestTest extends CakeTestCase {
public function testGetParamWithUrlencodedElement() {
$_GET = array();
$_GET['/posts/add/∂∂'] = '';
$_SERVER['PHP_SELF'] = '/app/webroot/index.php';
$_SERVER['REQUEST_URI'] = '/posts/add/%E2%88%82%E2%88%82';
$request = new CakeRequest();
$this->assertEquals('', $request->base);
$this->assertEquals(array(), $request->query);
$_GET = array();
$_GET['/cake_dev/posts/add/∂∂'] = '';
$_SERVER['PHP_SELF'] = '/cake_dev/app/webroot/index.php';
$_SERVER['REQUEST_URI'] = '/cake_dev/posts/add/%E2%88%82%E2%88%82';
$request = new CakeRequest();
$this->assertEquals('/cake_dev', $request->base);
$this->assertEquals(array(), $request->query);
}
@ -1877,6 +1893,34 @@ class CakeRequestTest extends CakeTestCase {
'urlParams' => array()
),
),
array(
'Nginx - w/rewrite, document root set above top level cake dir, request root, no PATH_INFO, base parameter set',
array(
'App' => array(
'base' => false,
'baseUrl' => false,
'dir' => 'app',
'webroot' => 'webroot'
),
'GET' => array('/site/posts/add' => ''),
'SERVER' => array(
'SERVER_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
'SCRIPT_NAME' => '/site/app/webroot/index.php',
'QUERY_STRING' => '/site/posts/add&',
'PHP_SELF' => '/site/app/webroot/index.php',
'PATH_INFO' => null,
'REQUEST_URI' => '/site/posts/add',
),
),
array(
'url' => 'posts/add',
'base' => '/site',
'webroot' => '/site/',
'urlParams' => array()
),
),
);
}