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

Commit 741e7a5

Browse files
committed
Merge branch 'hotfix/301'
Close #301
2 parents 2d0923f + 1eac731 commit 741e7a5

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
## 1.7.2 - TBD
5+
## 1.7.2 - 2018-05-29
66

77
### Added
88

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

2323
### Fixed
2424

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

2728
## 1.7.1 - 2018-02-26
2829

src/Uri.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function __construct($uri = '')
118118
));
119119
}
120120

121-
if (! empty($uri)) {
121+
if ('' !== $uri) {
122122
$this->parseUri($uri);
123123
}
124124
}
@@ -167,12 +167,12 @@ public function getScheme()
167167
*/
168168
public function getAuthority()
169169
{
170-
if (empty($this->host)) {
170+
if ('' === $this->host) {
171171
return '';
172172
}
173173

174174
$authority = $this->host;
175-
if (! empty($this->userInfo)) {
175+
if ('' !== $this->userInfo) {
176176
$authority = $this->userInfo . '@' . $authority;
177177
}
178178

@@ -496,27 +496,26 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
496496
{
497497
$uri = '';
498498

499-
if (! empty($scheme)) {
499+
if ('' !== $scheme) {
500500
$uri .= sprintf('%s:', $scheme);
501501
}
502502

503-
if (! empty($authority)) {
503+
if ('' !== $authority) {
504504
$uri .= '//' . $authority;
505505
}
506506

507-
if ($path) {
508-
if (empty($path) || '/' !== substr($path, 0, 1)) {
509-
$path = '/' . $path;
510-
}
511-
512-
$uri .= $path;
507+
if ('' !== $path && '/' !== substr($path, 0, 1)) {
508+
$path = '/' . $path;
513509
}
514510

515-
if ($query) {
511+
$uri .= $path;
512+
513+
514+
if ('' !== $query) {
516515
$uri .= sprintf('?%s', $query);
517516
}
518517

519-
if ($fragment) {
518+
if ('' !== $fragment) {
520519
$uri .= sprintf('#%s', $fragment);
521520
}
522521

@@ -533,14 +532,11 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
533532
*/
534533
private function isNonStandardPort($scheme, $host, $port)
535534
{
536-
if (! $scheme) {
537-
if ($host && ! $port) {
538-
return false;
539-
}
540-
return true;
535+
if ('' === $scheme) {
536+
return '' === $host || null !== $port;
541537
}
542538

543-
if (! $host || ! $port) {
539+
if ('' === $host || null === $port) {
544540
return false;
545541
}
546542

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

562-
if (empty($scheme)) {
558+
if ('' === $scheme) {
563559
return '';
564560
}
565561

@@ -605,7 +601,7 @@ private function filterPath($path)
605601
$path
606602
);
607603

608-
if (empty($path)) {
604+
if ('' === $path) {
609605
// No path
610606
return $path;
611607
}
@@ -629,7 +625,7 @@ private function filterPath($path)
629625
*/
630626
private function filterQuery($query)
631627
{
632-
if (! empty($query) && strpos($query, '?') === 0) {
628+
if ('' !== $query && strpos($query, '?') === 0) {
633629
$query = substr($query, 1);
634630
}
635631

@@ -673,7 +669,7 @@ private function splitQueryValue($value)
673669
*/
674670
private function filterFragment($fragment)
675671
{
676-
if (! empty($fragment) && strpos($fragment, '#') === 0) {
672+
if ('' !== $fragment && strpos($fragment, '#') === 0) {
677673
$fragment = '%23' . substr($fragment, 1);
678674
}
679675

test/UriTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,4 +691,12 @@ public function testHostIsLowercaseWhenIsSetViwWithHost()
691691
$uri = (new Uri())->withHost('NEW-HOST.COM');
692692
$this->assertSame('new-host.com', $uri->getHost());
693693
}
694+
695+
696+
public function testUriDistinguishZeroFromEmptyString()
697+
{
698+
$expected = 'https://0:0@0:1/0?0#0';
699+
$uri = new Uri($expected);
700+
$this->assertSame($expected, (string) $uri);
701+
}
694702
}

0 commit comments

Comments
 (0)