Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always parse query string, on the main request or on sub-requests #693

Merged
merged 3 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions classes/Kohana/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,9 @@ public function __construct($uri, $client_params = array(), $allow_external = TR
$split_uri = explode('?', $uri);
$uri = array_shift($split_uri);

// Initial request has global $_GET already applied
if (Request::$initial === NULL)
if ($split_uri)
{
if ($split_uri)
{
parse_str($split_uri[0], $this->_get);
}
parse_str($split_uri[0], $this->_get);
}

// Detect protocol (if present)
Expand Down
38 changes: 33 additions & 5 deletions tests/kohana/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public function provider_query_parameter_parsing()
{
return array(
array(
new Request('foo/bar'),
'foo/bar',
array(
'foo' => 'bar',
'sna' => 'fu'
Expand All @@ -631,7 +631,7 @@ public function provider_query_parameter_parsing()
),
),
array(
new Request('foo/bar?john=wayne&peggy=sue'),
'foo/bar?john=wayne&peggy=sue',
array(
'foo' => 'bar',
'sna' => 'fu'
Expand All @@ -644,7 +644,7 @@ public function provider_query_parameter_parsing()
),
),
array(
new Request('http://host.tld/foo/bar?john=wayne&peggy=sue'),
'http://host.tld/foo/bar?john=wayne&peggy=sue',
array(
'foo' => 'bar',
'sna' => 'fu'
Expand All @@ -664,13 +664,41 @@ public function provider_query_parameter_parsing()
*
* @dataProvider provider_query_parameter_parsing
*
* @param Request request
* @param string url
* @param array query
* @param array expected
* @return void
*/
public function test_query_parameter_parsing(Request $request, $query, $expected)
public function test_query_parameter_parsing($url, $query, $expected)
{
Request::$initial = NULL;

$request = new Request($url);

foreach ($query as $key => $value)
{
$request->query($key, $value);
}

$this->assertSame($expected, $request->query());
}

/**
* Tests that query parameters are parsed correctly
*
* @dataProvider provider_query_parameter_parsing
*
* @param string url
* @param array query
* @param array expected
* @return void
*/
public function test_query_parameter_parsing_in_subrequest($url, $query, $expected)
{
Request::$initial = new Request(TRUE);

$request = new Request($url);

foreach ($query as $key => $value)
{
$request->query($key, $value);
Expand Down