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

Commit

Permalink
Merge branch 'hotfix/293'
Browse files Browse the repository at this point in the history
Close #293
Fixes #292
  • Loading branch information
weierophinney committed Feb 26, 2018
2 parents b57ec28 + 88fcaea commit f237ca5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ All notable changes to this project will be documented in this file, in reverse

### Changed

- Nothing.
- [#293](https://github.com/zendframework/zend-diactoros/pull/293) updates
`Uri::getHost()` to cast the value via `strtolower()` before returning it.
While this represents a change, it is fixing a bug in our implementation:
the PSR-7 specification for the method, which follows IETF RFC 3986 section
3.2.2, requires that the host name be normalized to lowercase.

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function withHost($host)
}

$new = clone $this;
$new->host = $host;
$new->host = strtolower($host);

return $new;
}
Expand Down Expand Up @@ -451,7 +451,7 @@ 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']) ? $parts['host'] : '';
$this->host = isset($parts['host']) ? strtolower($parts['host']) : '';
$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']) : '';
Expand Down
12 changes: 12 additions & 0 deletions test/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,16 @@ public function testReservedCharsInPathUnencoded()

$this->assertContains('/v1/people/~:(first-name,last-name,email-address,picture-url)', (string) $uri);
}

public function testHostIsLowercase()
{
$uri = new Uri('http://HOST.LOC/path?q=1');
$this->assertSame('host.loc', $uri->getHost());
}

public function testHostIsLowercaseWhenIsSetViwWithHost()
{
$uri = (new Uri())->withHost('NEW-HOST.COM');
$this->assertSame('new-host.com', $uri->getHost());
}
}

0 comments on commit f237ca5

Please sign in to comment.