From 304117d2289b2cb6f8f91fd06531eb8b2c962e4d Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 4 Jan 2017 22:34:19 -0500 Subject: [PATCH] Fix query string parsing on requestAction() This also fixes a long standing oddity around string URLs that include a query string where the query string data would be duplicated. Refs #9962 --- lib/Cake/Network/CakeRequest.php | 2 +- lib/Cake/Test/Case/Core/CakeObjectTest.php | 13 ++++++++++++- lib/Cake/Test/Case/Network/CakeRequestTest.php | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 8d1058a14..7a12ec155 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -223,7 +223,7 @@ class CakeRequest implements ArrayAccess { unset($query[$unsetUrl]); unset($query[$this->base . $unsetUrl]); if (strpos($this->url, '?') !== false) { - list(, $querystr) = explode('?', $this->url); + list($this->url, $querystr) = explode('?', $this->url); parse_str($querystr, $queryArgs); $query += $queryArgs; } diff --git a/lib/Cake/Test/Case/Core/CakeObjectTest.php b/lib/Cake/Test/Case/Core/CakeObjectTest.php index ace73535a..d8fb48c5a 100644 --- a/lib/Cake/Test/Case/Core/CakeObjectTest.php +++ b/lib/Cake/Test/Case/Core/CakeObjectTest.php @@ -86,7 +86,7 @@ class RequestActionController extends Controller { * @return string $this->here. */ public function return_here() { - return $this->here; + return $this->request->here(); } /** @@ -483,6 +483,17 @@ class ObjectTest extends CakeTestCase { $this->assertNull(Router::getRequest(), 'requests were not popped off the stack, this will break url generation'); } +/** + * Test that here() is calculated correctly in requestAction + * + * @return void + */ + public function testRequestActionHere() { + $url = '/request_action/return_here?key=value'; + $result = $this->object->requestAction($url); + $this->assertStringEndsWith($url, $result); + } + /** * test requestAction() and plugins. * diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 46774d8ce..64f8a14f9 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -193,7 +193,8 @@ class CakeRequestTest extends CakeTestCase { $request = new CakeRequest('some/path?one=something&two=else'); $expected = array('one' => 'something', 'two' => 'else'); $this->assertEquals($expected, $request->query); - $this->assertEquals('some/path?one=something&two=else', $request->url); + $this->assertEquals('some/path', $request->url); + $this->assertStringEndsWith('/some/path?one=something&two=else', $request->here()); } /**