diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 23c014170..e9d9aeaaa 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -185,7 +185,7 @@ class CakeRequest implements ArrayAccess { $query = $_GET; } - unset($query['/' . str_replace('.', '_', $this->url)]); + unset($query['/' . str_replace('.', '_', urldecode($this->url))]); if (strpos($this->url, '?') !== false) { list(, $querystr) = explode('?', $this->url); parse_str($querystr, $queryArgs); diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index e0e42c977..927d23245 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -225,7 +225,13 @@ class CakeRoute { } $route[$key] = $value; } - + + foreach ($this->keys as $key) { + if (isset($route[$key])) { + $route[$key] = rawurldecode($route[$key]); + } + } + if (isset($route['_args_'])) { list($pass, $named) = $this->_parseArgs($route['_args_'], $route); $route['pass'] = array_merge($route['pass'], $pass); diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index f2d399916..e879bb428 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1120,6 +1120,20 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals(array(), $request->query); } +/** + * Test that a request with urlencoded bits in the main GET parameter are filtered out. + * + * @return void + */ + public function testGetParamWithUrlencodedElement() { + $_GET['/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(array(), $request->query); + } + /** * generator for environment configurations * diff --git a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php index 28d7cbce5..9dba06fb0 100644 --- a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php +++ b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php @@ -508,6 +508,28 @@ class CakeRouteTest extends CakeTestCase { $this->assertEquals($result['action'], 'index'); } +/** + * Test that :key elements are urldecoded + * + * @return void + */ + public function testParseUrlDecodeElements() { + $route = new Cakeroute( + '/:controller/:slug', + array('action' => 'view') + ); + $route->compile(); + $result = $route->parse('/posts/%E2%88%82%E2%88%82'); + $this->assertEquals($result['controller'], 'posts'); + $this->assertEquals($result['action'], 'view'); + $this->assertEquals($result['slug'], '∂∂'); + + $result = $route->parse('/posts/∂∂'); + $this->assertEquals($result['controller'], 'posts'); + $this->assertEquals($result['action'], 'view'); + $this->assertEquals($result['slug'], '∂∂'); + } + /** * test numerically indexed defaults, get appeneded to pass *