Permalink
Browse files

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
  • Loading branch information...
1 parent bbd6e22 commit b7f6645cec8fddea9318a53c99b138b55b5fb23a @markstory markstory committed Dec 9, 2011
Showing with 18 additions and 2 deletions.
  1. +1 −1 lib/Cake/Network/CakeRequest.php
  2. +17 −1 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -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 '/';
@@ -104,12 +104,27 @@ 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
*
* @return void
@@ -1623,6 +1638,7 @@ public function testInputDecodeExtraParams() {
);
}
+
/**
* loadEnvironment method
*

0 comments on commit b7f6645

Please sign in to comment.