Skip to content

Commit 2565092

Browse files
Merge branch '3.4' into 4.2
* 3.4: Fix Twig 1.x compatibility [Translator] Improve farsi(persian) translations for Form Improve fa translations Added tests to cover the possibility of having scalars as services. fixed tests on old PHP versions [FrameworkBundle] Inform the user when save_path will be ignored fixed CS [Translator] Load plurals from po files properly [EventDispatcher] Add tag kernel.rest on 'debug.event_dispatcher' service [Console] Update to inherit and add licence [Intl] Remove --dev from intl compile autoloader [Intl] Init compile tmp volume PHP 5 compat Add test case Update Request.php Don't assume port 0 for X-Forwarded-Port Load plurals from mo files properly
2 parents b8d9ff2 + 8d530ef commit 2565092

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,8 @@ public function getPort()
913913
$pos = strrpos($host, ':');
914914
}
915915

916-
if (false !== $pos) {
917-
return (int) substr($host, $pos + 1);
916+
if (false !== $pos && $port = substr($host, $pos + 1)) {
917+
return (int) $port;
918918
}
919919

920920
return 'https' === $this->getScheme() ? 443 : 80;

Tests/RequestTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,18 @@ public function testTrustedPort()
23032303

23042304
$this->assertSame(443, $request->getPort());
23052305
}
2306+
2307+
public function testTrustedPortDoesNotDefaultToZero()
2308+
{
2309+
Request::setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_ALL);
2310+
2311+
$request = Request::create('/');
2312+
$request->server->set('REMOTE_ADDR', '1.1.1.1');
2313+
$request->headers->set('X-Forwarded-Host', 'test.example.com');
2314+
$request->headers->set('X-Forwarded-Port', '');
2315+
2316+
$this->assertSame(80, $request->getPort());
2317+
}
23062318
}
23072319

23082320
class RequestContentProxy extends Request

0 commit comments

Comments
 (0)