diff --git a/src/Uri.php b/src/Uri.php index d9833f63..1cd139df 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -471,7 +471,9 @@ private function parseUri($uri) $this->scheme = isset($parts['scheme']) ? $this->filterScheme($parts['scheme']) : ''; $this->userInfo = isset($parts['user']) ? $this->filterUserInfoPart($parts['user']) : ''; - $this->host = isset($parts['host']) ? strtolower($parts['host']) : ''; + $this->host = isset($parts['host']) + ? strtolower($parts['host']) . ($this->scheme === 'https' && (isset($parts['port']) && $parts['port'] !== 80) ? ':' . $parts['port'] : null) + : ''; $this->port = isset($parts['port']) ? $parts['port'] : null; $this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : ''; $this->query = isset($parts['query']) ? $this->filterQuery($parts['query']) : ''; diff --git a/test/UriTest.php b/test/UriTest.php index f38c4b50..c4e8b22f 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -692,6 +692,23 @@ public function testHostIsLowercaseWhenIsSetViwWithHost() $this->assertSame('new-host.com', $uri->getHost()); } + public function testGetHttpsHostWithSpecifiedPortNon80() + { + $uri = new Uri('https://example.com:443'); + $this->assertSame('example.com:443', $uri->getHost()); + } + + public function testGetHttpsHostWithSpecifiedPort80() + { + $uri = new Uri('https://example.com:80'); + $this->assertSame('example.com', $uri->getHost()); + } + + public function testGetHttpsHostWithoutSpecifiedPort() + { + $uri = new Uri('https://example.com'); + $this->assertSame('example.com', $uri->getHost()); + } public function testUriDistinguishZeroFromEmptyString() {