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

Commit

Permalink
Merge 56b7c19 into b511ac0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtagliab committed Sep 30, 2019
2 parents b511ac0 + 56b7c19 commit d8c018a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Uri.php
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
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($uri->getHost(), 'www.example.com');
$this->assertSame($uri->getPort(), null);
}
}

0 comments on commit d8c018a

Please sign in to comment.