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

Commit 6053be4

Browse files
committed
Merge branch 'hotfix/34'
Close #34 Fix #33
2 parents 81af14a + 9778845 commit 6053be4

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
- [#34](https://github.com/zendframework/zend-uri/pull/34) fixes hostname recognition
26+
when port number is not provided. Additional colon is stripped out.
2627

2728
## 2.7.0 - 2019-02-27
2829

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)