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

Commit f237ca5

Browse files
committed
Merge branch 'hotfix/293'
Close #293 Fixes #292
2 parents b57ec28 + 88fcaea commit f237ca5

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ All notable changes to this project will be documented in this file, in reverse
1010

1111
### Changed
1212

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

1519
### Deprecated
1620

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)