Skip to content

Commit

Permalink
bug #34649 more robust initialization from request (dbu)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

more robust initialization from request

Request::getPort is declared as int|string but can actually return null.

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

I discovered this problem with a functional test where i dispatch the RequestEvent with a `new Request()`. This used to work in symfony 4 and now triggers an error `Argument 1 passed to Symfony\Component\Routing\RequestContext::setHttpPort() must be of the type int, null given`

In regular web requests, this should probably never happen, but it seems to me if Request is not robust, the RequestContext should be robust about it.

Commits
-------

c6ed0f0 more robust initialization from request
  • Loading branch information
fabpot committed Nov 30, 2019
2 parents d2a5c05 + c6ed0f0 commit 9b3cc04
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Routing/RequestContext.php
Expand Up @@ -67,8 +67,8 @@ public function fromRequest(Request $request)
$this->setMethod($request->getMethod());
$this->setHost($request->getHost());
$this->setScheme($request->getScheme());
$this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
$this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
$this->setHttpPort($request->isSecure() || null === $request->getPort() ? $this->httpPort : $request->getPort());
$this->setHttpsPort($request->isSecure() && null !== $request->getPort() ? $request->getPort() : $this->httpsPort);
$this->setQueryString($request->server->get('QUERY_STRING', ''));

return $this;
Expand Down

0 comments on commit 9b3cc04

Please sign in to comment.