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/301'
Browse files Browse the repository at this point in the history
Close #301
  • Loading branch information
weierophinney committed May 29, 2018
2 parents 2d0923f + 1eac731 commit 741e7a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.7.2 - TBD
## 1.7.2 - 2018-05-29

### Added

Expand All @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#301](https://github.com/zendframework/zend-diactoros/pull/301) adds stricter comparisons within the `uri` class to ensure non-empty
values are not treated as empty.

## 1.7.1 - 2018-02-26

Expand Down
42 changes: 19 additions & 23 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function __construct($uri = '')
));
}

if (! empty($uri)) {
if ('' !== $uri) {
$this->parseUri($uri);
}
}
Expand Down Expand Up @@ -167,12 +167,12 @@ public function getScheme()
*/
public function getAuthority()
{
if (empty($this->host)) {
if ('' === $this->host) {
return '';
}

$authority = $this->host;
if (! empty($this->userInfo)) {
if ('' !== $this->userInfo) {
$authority = $this->userInfo . '@' . $authority;
}

Expand Down Expand Up @@ -496,27 +496,26 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
{
$uri = '';

if (! empty($scheme)) {
if ('' !== $scheme) {
$uri .= sprintf('%s:', $scheme);
}

if (! empty($authority)) {
if ('' !== $authority) {
$uri .= '//' . $authority;
}

if ($path) {
if (empty($path) || '/' !== substr($path, 0, 1)) {
$path = '/' . $path;
}

$uri .= $path;
if ('' !== $path && '/' !== substr($path, 0, 1)) {
$path = '/' . $path;
}

if ($query) {
$uri .= $path;


if ('' !== $query) {
$uri .= sprintf('?%s', $query);
}

if ($fragment) {
if ('' !== $fragment) {
$uri .= sprintf('#%s', $fragment);
}

Expand All @@ -533,14 +532,11 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
*/
private function isNonStandardPort($scheme, $host, $port)
{
if (! $scheme) {
if ($host && ! $port) {
return false;
}
return true;
if ('' === $scheme) {
return '' === $host || null !== $port;
}

if (! $host || ! $port) {
if ('' === $host || null === $port) {
return false;
}

Expand All @@ -559,7 +555,7 @@ private function filterScheme($scheme)
$scheme = strtolower($scheme);
$scheme = preg_replace('#:(//)?$#', '', $scheme);

if (empty($scheme)) {
if ('' === $scheme) {
return '';
}

Expand Down Expand Up @@ -605,7 +601,7 @@ private function filterPath($path)
$path
);

if (empty($path)) {
if ('' === $path) {
// No path
return $path;
}
Expand All @@ -629,7 +625,7 @@ private function filterPath($path)
*/
private function filterQuery($query)
{
if (! empty($query) && strpos($query, '?') === 0) {
if ('' !== $query && strpos($query, '?') === 0) {
$query = substr($query, 1);
}

Expand Down Expand Up @@ -673,7 +669,7 @@ private function splitQueryValue($value)
*/
private function filterFragment($fragment)
{
if (! empty($fragment) && strpos($fragment, '#') === 0) {
if ('' !== $fragment && strpos($fragment, '#') === 0) {
$fragment = '%23' . substr($fragment, 1);
}

Expand Down
8 changes: 8 additions & 0 deletions test/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,12 @@ public function testHostIsLowercaseWhenIsSetViwWithHost()
$uri = (new Uri())->withHost('NEW-HOST.COM');
$this->assertSame('new-host.com', $uri->getHost());
}


public function testUriDistinguishZeroFromEmptyString()
{
$expected = 'https://0:0@0:1/0?0#0';
$uri = new Uri($expected);
$this->assertSame($expected, (string) $uri);
}
}

0 comments on commit 741e7a5

Please sign in to comment.