Skip to content

Commit

Permalink
Fix issue with url parsing and /?
Browse files Browse the repository at this point in the history
PHP's parse_url fails to parse url's containing
`/?`.  It returns false instead of something useful.

Fixes #2354
  • Loading branch information
markstory committed Dec 9, 2011
1 parent bbd6e22 commit b7f6645
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Network/CakeRequest.php
Expand Up @@ -222,7 +222,7 @@ protected function _url() {
$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 '/';
Expand Down
18 changes: 17 additions & 1 deletion lib/Cake/Test/Case/Network/CakeRequestTest.php
Expand Up @@ -104,11 +104,26 @@ public function testQueryStringParsingFromInputUrl() {
$_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
*
Expand Down Expand Up @@ -1623,6 +1638,7 @@ public function testInputDecodeExtraParams() {
);
}


/**
* loadEnvironment method
*
Expand Down

0 comments on commit b7f6645

Please sign in to comment.