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

Commit dd43895

Browse files
committed
getHost returns always lowercase hostname (PSR-7 spec)
Fixes #292
1 parent b57ec28 commit dd43895

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Uri.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public function withHost($host)
303303
}
304304

305305
$new = clone $this;
306-
$new->host = $host;
306+
$new->host = strtolower($host);
307307

308308
return $new;
309309
}
@@ -451,7 +451,7 @@ private function parseUri($uri)
451451

452452
$this->scheme = isset($parts['scheme']) ? $this->filterScheme($parts['scheme']) : '';
453453
$this->userInfo = isset($parts['user']) ? $this->filterUserInfoPart($parts['user']) : '';
454-
$this->host = isset($parts['host']) ? $parts['host'] : '';
454+
$this->host = isset($parts['host']) ? strtolower($parts['host']) : '';
455455
$this->port = isset($parts['port']) ? $parts['port'] : null;
456456
$this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : '';
457457
$this->query = isset($parts['query']) ? $this->filterQuery($parts['query']) : '';

test/UriTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,4 +677,16 @@ public function testReservedCharsInPathUnencoded()
677677

678678
$this->assertContains('/v1/people/~:(first-name,last-name,email-address,picture-url)', (string) $uri);
679679
}
680+
681+
public function testHostIsLowercase()
682+
{
683+
$uri = new Uri('http://HOST.LOC/path?q=1');
684+
$this->assertSame('host.loc', $uri->getHost());
685+
}
686+
687+
public function testHostIsLowercaseWhenIsSetViwWithHost()
688+
{
689+
$uri = (new Uri())->withHost('NEW-HOST.COM');
690+
$this->assertSame('new-host.com', $uri->getHost());
691+
}
680692
}

0 commit comments

Comments
 (0)