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

Commit

Permalink
Merge 1f4b6c7 into b511ac0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtagliab committed Sep 23, 2019
2 parents b511ac0 + 1f4b6c7 commit 81d41e7
Show file tree
Hide file tree
Showing 2 changed files with 17 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);

// 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);
}

$this->setPort((int) $port);
$authority = substr($authority, 0, -$portLength);
}

Expand Down
10 changes: 10 additions & 0 deletions test/UriTest.php
Expand Up @@ -1371,4 +1371,14 @@ 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 81d41e7

Please sign in to comment.