Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Update QUERY_STRING when overrideGlobals #11408

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

Merged
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
2 changes: 2 additions & 0 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ public function __toString()
*/
public function overrideGlobals()
{
$this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), null, '&')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be $_SERVER['QUERY_STRING'] = static::... instead (and moved after the main $_SERVER assignation). But I don't see why this would be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A use case is when you want to get the current URI without some GET parameters:

$request->query->remove('nonce');
$redirectUri = $request->getUri();

I code it like this at the first position because getUri() uses getQueryString() that gets the query string from $this->server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot does this need something else?


$_GET = $this->query->all();
$_POST = $this->request->all();
$_SERVER = $this->server->all();
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,15 @@ public function testOverrideGlobals()

$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;
}
Expand Down