Skip to content

Commit 54afc18

Browse files
committed
RequestFactory: strips trailing . from host
1 parent 8874de4 commit 54afc18

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/Http/RequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function getServer(Url $url): void
9191
(isset($_SERVER[$tmp = 'HTTP_HOST']) || isset($_SERVER[$tmp = 'SERVER_NAME']))
9292
&& preg_match('#^([a-z0-9_.-]+|\[[a-f0-9:]+\])(:\d+)?$#Di', $_SERVER[$tmp], $pair)
9393
) {
94-
$url->setHost(strtolower($pair[1]));
94+
$url->setHost(rtrim(strtolower($pair[1]), '.'));
9595
if (isset($pair[2])) {
9696
$url->setPort((int) substr($pair[2], 1));
9797
} elseif (isset($_SERVER['SERVER_PORT'])) {

tests/Http/RequestFactory.host.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ $factory = new RequestFactory;
4848
Assert::same('http:/', (string) $factory->fromGlobals()->getUrl());
4949

5050

51+
$_SERVER = [
52+
'HTTP_HOST' => 'a.cz.',
53+
];
54+
$factory = new RequestFactory;
55+
Assert::same('http://a.cz/', (string) $factory->fromGlobals()->getUrl());
56+
57+
5158
$_SERVER = [
5259
'HTTP_HOST' => 'AB',
5360
];

0 commit comments

Comments
 (0)