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

Commit 7e53de0

Browse files
committed
Merge pull request #34 from mtagliab/develop
URI with ending colon without port
2 parents 81af14a + 1cb32be commit 7e53de0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Uri.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,17 @@ public function parse($uri)
301301
$this->setUserInfo($userInfo);
302302
}
303303

304-
$nMatches = preg_match('/:[\d]{1,5}$/', $authority, $matches);
304+
$nMatches = preg_match('/:[\d]{0,5}$/', $authority, $matches);
305305
if ($nMatches === 1) {
306306
$portLength = strlen($matches[0]);
307307
$port = substr($matches[0], 1);
308308

309-
$this->setPort((int) $port);
309+
// If authority ends with colon, port will be empty string.
310+
// Remove the colon from authority, but keeps port null
311+
if ($port) {
312+
$this->setPort((int) $port);
313+
}
314+
310315
$authority = substr($authority, 0, -$portLength);
311316
}
312317

test/UriTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,4 +1371,13 @@ public function testReservedCharsInPathUnencoded()
13711371
$uri->toString()
13721372
);
13731373
}
1374+
1375+
public function testUriWithEndingColonWithoutPort()
1376+
{
1377+
$uriString = 'http://www.example.com:';
1378+
$uri = new Uri($uriString);
1379+
1380+
$this->assertSame('www.example.com', $uri->getHost());
1381+
$this->assertNull($uri->getPort());
1382+
}
13741383
}

0 commit comments

Comments
 (0)