Fix issue with url parsing and /?

PHP's parse_url fails to parse url's containing
`/?`.  It returns false instead of something useful.

Fixes #2354
This commit is contained in:
mark_story 2011-12-08 21:48:40 -05:00
parent bbd6e22e26
commit b7f6645cec
2 changed files with 18 additions and 2 deletions

View file

@ -222,7 +222,7 @@ class CakeRequest implements ArrayAccess {
$uri = substr($uri, strlen($base));
}
if (strpos($uri, '?') !== false) {
$uri = parse_url($uri, PHP_URL_PATH);
list($uri) = explode('?', $uri, 2);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
return '/';

View file

@ -104,11 +104,26 @@ class CakeRequestTest extends CakeTestCase {
$_GET = array();
$request = new CakeRequest('some/path?one=something&two=else');
$expected = array('one' => 'something', 'two' => 'else');
$this->assertEquals($request->query, $expected);
$this->assertEquals($expected, $request->query);
$this->assertEquals('some/path?one=something&two=else', $request->url);
}
/**
* Test that named arguments + querystrings are handled correctly.
*
* @return void
*/
public function testQueryStringAndNamedParams() {
$_SERVER['REQUEST_URI'] = '/tasks/index/page:1?ts=123456';
$request = new CakeRequest();
$this->assertEquals('tasks/index/page:1', $request->url);
$_SERVER['REQUEST_URI'] = '/tasks/index/page:1/?ts=123456';
$request = new CakeRequest();
$this->assertEquals('tasks/index/page:1/', $request->url);
}
/**
* test addParams() method
*
@ -1623,6 +1638,7 @@ XML;
);
}
/**
* loadEnvironment method
*