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
This commit is contained in:
mark_story 2017-01-04 22:34:19 -05:00
parent 7e187a4e41
commit 304117d228
3 changed files with 15 additions and 3 deletions

View file

@ -223,7 +223,7 @@ class CakeRequest implements ArrayAccess {
unset($query[$unsetUrl]); unset($query[$unsetUrl]);
unset($query[$this->base . $unsetUrl]); unset($query[$this->base . $unsetUrl]);
if (strpos($this->url, '?') !== false) { if (strpos($this->url, '?') !== false) {
list(, $querystr) = explode('?', $this->url); list($this->url, $querystr) = explode('?', $this->url);
parse_str($querystr, $queryArgs); parse_str($querystr, $queryArgs);
$query += $queryArgs; $query += $queryArgs;
} }

View file

@ -86,7 +86,7 @@ class RequestActionController extends Controller {
* @return string $this->here. * @return string $this->here.
*/ */
public function return_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'); $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. * test requestAction() and plugins.
* *

View file

@ -193,7 +193,8 @@ class CakeRequestTest extends CakeTestCase {
$request = new CakeRequest('some/path?one=something&two=else'); $request = new CakeRequest('some/path?one=something&two=else');
$expected = array('one' => 'something', 'two' => 'else'); $expected = array('one' => 'something', 'two' => 'else');
$this->assertEquals($expected, $request->query); $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());
} }
/** /**