Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit fec4cec

Browse files
committed
Merge branch 'hotfix/zf2-499'
6 parents 24efdcc + 219c9ad + 3025666 + e9fa593 + 2844dba + e5520e9 commit fec4cec

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/PhpEnvironment/Request.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ public function setServer(ParametersInterface $server)
264264
if (isset($this->serverParams['SERVER_PORT'])) {
265265
$port = (int) $this->serverParams['SERVER_PORT'];
266266
}
267+
// Check for missinterpreted IPv6-Address
268+
// Reported at least for Safari on Windows
269+
if (isset($this->serverParams['SERVER_ADDR']) && preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
270+
$host = '[' . $this->serverParams['SERVER_ADDR'] . ']';
271+
if ($port . ']' == substr($host, strrpos($host, ':')+1)) {
272+
// The last digit of the IPv6-Address has been taken as port
273+
// Unset the port so the default port can be used
274+
$port = null;
275+
}
276+
}
267277
} elseif ($this->getHeaders()->get('host')) {
268278
$host = $this->getHeaders()->get('host')->getFieldValue();
269279
// works for regname, IPv4 & IPv6

test/PhpEnvironment/RequestTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public static function serverHostnameProvider()
301301
'REQUEST_URI' => 'http://test.example.com/news',
302302
),
303303
'test.example.com',
304+
'80',
304305
'/news',
305306
),
306307
array(
@@ -309,6 +310,30 @@ public static function serverHostnameProvider()
309310
'REQUEST_URI' => 'http://test.example.com/news',
310311
),
311312
'test.example.com',
313+
'80',
314+
'/news',
315+
),
316+
array(
317+
array(
318+
'SERVER_NAME' => '[1:2:3:4:5:6::6]',
319+
'SERVER_ADDR' => '1:2:3:4:5:6::6',
320+
'SERVER_PORT' => '80',
321+
'REQUEST_URI' => 'http://[1:2:3:4:5:6::6]/news',
322+
),
323+
'[1:2:3:4:5:6::6]',
324+
'80',
325+
'/news',
326+
),
327+
// Test for broken $_SERVER implementation from Windows-Safari
328+
array(
329+
array(
330+
'SERVER_NAME' => '[1:2:3:4:5:6:]',
331+
'SERVER_ADDR' => '1:2:3:4:5:6::6',
332+
'SERVER_PORT' => '6',
333+
'REQUEST_URI' => 'http://[1:2:3:4:5:6::6]/news',
334+
),
335+
'[1:2:3:4:5:6::6]',
336+
'80',
312337
'/news',
313338
),
314339
array(
@@ -318,6 +343,7 @@ public static function serverHostnameProvider()
318343
'REQUEST_URI' => 'http://test.example.com/news',
319344
),
320345
'test.example.com',
346+
'8080',
321347
'/news',
322348
),
323349
array(
@@ -328,6 +354,7 @@ public static function serverHostnameProvider()
328354
'REQUEST_URI' => 'https://test.example.com/news',
329355
),
330356
'test.example.com',
357+
'443',
331358
'/news',
332359
),
333360
);
@@ -339,14 +366,17 @@ public static function serverHostnameProvider()
339366
* @param string $name
340367
* @param string $value
341368
*/
342-
public function testServerHostnameProvider(array $server, $expectedHost, $expectedRequestUri)
369+
public function testServerHostnameProvider(array $server, $expectedHost, $expectedPort, $expectedRequestUri)
343370
{
344371
$_SERVER = $server;
345372
$request = new Request();
346373

347374
$host = $request->getUri()->getHost();
348375
$this->assertEquals($expectedHost, $host);
349376

377+
$port = $request->getUri()->getPort();
378+
$this->assertEquals($expectedPort, $port);
379+
350380
$requestUri = $request->getRequestUri();
351381
$this->assertEquals($expectedRequestUri, $requestUri);
352382
}

0 commit comments

Comments
 (0)