From b06c83062b9571452ad49879e820a7e846645c8e Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Sat, 4 Mar 2017 12:06:11 +0100 Subject: [PATCH] Improve SERVER_PORT fix --- CHANGELOG.md | 18 ++++++++++++++++++ src/Http.php | 6 ++++-- tests/HttpTest.php | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef65997..d7834fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All Notable changes to `League\Uri\Components` will be documented in this file +## 1.0.3 - TBD + +### Added + +- None + +### Fixed + +- Bug fix `$_SERVER['SERVER_PORT']` valui with `League\Uri\Schemes\Http::createFromServer` see [#PR1](https://github.com/thephpleague/uri-schemes/pull/1) + +### Deprecated + +- None + +### Removed + +- None + ## 1.0.2 - 2017-03-01 ### Added diff --git a/src/Http.php b/src/Http.php index d1116dc..a88351d 100644 --- a/src/Http.php +++ b/src/Http.php @@ -69,8 +69,6 @@ public static function createFromServer(array $server): self list($host, $port) = static::fetchHostname($server); list($path, $query) = static::fetchRequestUri($server); - $port = $port !== null ? (int) $port : $port; - return new static(static::fetchScheme($server), $user, $pass, $host, $port, $path, $query); } @@ -130,6 +128,10 @@ protected static function fetchUserInfo(array $server): array protected static function fetchHostname(array $server): array { $server += ['SERVER_PORT' => null]; + if (null !== $server['SERVER_PORT']) { + $server['SERVER_PORT'] = (int) $server['SERVER_PORT']; + } + if (isset($server['HTTP_HOST'])) { preg_match(',^(?(\[.*\]|[^:])*)(\:(?[^/?\#]*))?$,x', $server['HTTP_HOST'], $matches); diff --git a/tests/HttpTest.php b/tests/HttpTest.php index 4321ee7..067438a 100644 --- a/tests/HttpTest.php +++ b/tests/HttpTest.php @@ -149,7 +149,7 @@ public function validServerArray() 'REQUEST_URI' => '', 'SERVER_ADDR' => '127.0.0.1', 'HTTPS' => 'on', - 'SERVER_PORT' => 23, + 'SERVER_PORT' => '23', 'HTTP_HOST' => 'example.com', ], ],