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

Commit

Permalink
Merge branch 'hotfix/34' into develop
Browse files Browse the repository at this point in the history
Forward port #34
  • Loading branch information
michalbundyra committed Oct 7, 2019
2 parents b511ac0 + 9778845 commit ca841e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#34](https://github.com/zendframework/zend-uri/pull/34) fixes hostname recognition
when port number is not provided. Additional colon is stripped out.

## 2.7.0 - 2019-02-27

Expand Down
9 changes: 7 additions & 2 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,17 @@ public function parse($uri)
$this->setUserInfo($userInfo);
}

$nMatches = preg_match('/:[\d]{1,5}$/', $authority, $matches);
$nMatches = preg_match('/:[\d]{0,5}$/', $authority, $matches);
if ($nMatches === 1) {
$portLength = strlen($matches[0]);
$port = substr($matches[0], 1);

$this->setPort((int) $port);
// If authority ends with colon, port will be empty string.
// Remove the colon from authority, but keeps port null
if ($port) {
$this->setPort((int) $port);
}

$authority = substr($authority, 0, -$portLength);
}

Expand Down
9 changes: 9 additions & 0 deletions test/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1371,4 +1371,13 @@ public function testReservedCharsInPathUnencoded()
$uri->toString()
);
}

public function testUriWithEndingColonWithoutPort()
{
$uriString = 'http://www.example.com:';
$uri = new Uri($uriString);

$this->assertSame('www.example.com', $uri->getHost());
$this->assertNull($uri->getPort());
}
}

0 comments on commit ca841e0

Please sign in to comment.