bug #11408 [HttpFoundation] Update QUERY_STRING when overrideGlobals (yguedidi)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpFoundation] Update QUERY_STRING when overrideGlobals

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

777666f [HttpFoundation] Update QUERY_STRING when overrideGlobals
This commit is contained in:
Nicolas Grekas 2014-08-13 21:04:07 +02:00
commit 511b20d837
2 changed files with 11 additions and 0 deletions

View File

@ -479,6 +479,8 @@ class Request
*/
public function overrideGlobals()
{
$this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null, '&')));
$_GET = $this->query->all();
$_POST = $this->request->all();
$_SERVER = $this->server->all();

View File

@ -1009,6 +1009,15 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('HTTP_X_FORWARDED_PROTO', $_SERVER);
$request->initialize(array('foo' => 'bar', 'baz' => 'foo'));
$request->query->remove('baz');
$request->overrideGlobals();
$this->assertEquals(array('foo' => 'bar'), $_GET);
$this->assertEquals('foo=bar', $_SERVER['QUERY_STRING']);
$this->assertEquals('foo=bar', $request->server->get('QUERY_STRING'));
// restore initial $_SERVER array
$_SERVER = $server;
}