Skip to content

Commit

Permalink
Merge pull request #693 from kohana/3.3/bugfix/always-parse-get
Browse files Browse the repository at this point in the history
Always parse query string, on the main request or on sub-requests
  • Loading branch information
enov authored Jul 25, 2016
2 parents 6546952 + 0505301 commit 277f6d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
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

0 comments on commit 277f6d7

Please sign in to comment.