Skip to content

Commit b7f6645

Browse files
committed
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
1 parent bbd6e22 commit b7f6645

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Cake/Network/CakeRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ protected function _url() {
222222
$uri = substr($uri, strlen($base));
223223
}
224224
if (strpos($uri, '?') !== false) {
225-
$uri = parse_url($uri, PHP_URL_PATH);
225+
list($uri) = explode('?', $uri, 2);
226226
}
227227
if (empty($uri) || $uri == '/' || $uri == '//') {
228228
return '/';

lib/Cake/Test/Case/Network/CakeRequestTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,26 @@ public function testQueryStringParsingFromInputUrl() {
104104
$_GET = array();
105105
$request = new CakeRequest('some/path?one=something&two=else');
106106
$expected = array('one' => 'something', 'two' => 'else');
107-
$this->assertEquals($request->query, $expected);
107+
$this->assertEquals($expected, $request->query);
108108
$this->assertEquals('some/path?one=something&two=else', $request->url);
109109

110110
}
111111

112+
/**
113+
* Test that named arguments + querystrings are handled correctly.
114+
*
115+
* @return void
116+
*/
117+
public function testQueryStringAndNamedParams() {
118+
$_SERVER['REQUEST_URI'] = '/tasks/index/page:1?ts=123456';
119+
$request = new CakeRequest();
120+
$this->assertEquals('tasks/index/page:1', $request->url);
121+
122+
$_SERVER['REQUEST_URI'] = '/tasks/index/page:1/?ts=123456';
123+
$request = new CakeRequest();
124+
$this->assertEquals('tasks/index/page:1/', $request->url);
125+
}
126+
112127
/**
113128
* test addParams() method
114129
*
@@ -1623,6 +1638,7 @@ public function testInputDecodeExtraParams() {
16231638
);
16241639
}
16251640

1641+
16261642
/**
16271643
* loadEnvironment method
16281644
*

0 commit comments

Comments
 (0)