From 2613fc1595bf424388b1acffec1406ee783bd1bb Mon Sep 17 00:00:00 2001 From: Matteo <5571458+mtagliab@users.noreply.github.com> Date: Fri, 20 Sep 2019 15:43:54 +0200 Subject: [PATCH 1/3] Remove ending colon from URI without port --- src/Uri.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Uri.php b/src/Uri.php index 964ba85ee..3e27270ea 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -301,10 +301,16 @@ 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); From 17d32d0e4b4021b6beeb5fc0499a0965c73ddf70 Mon Sep 17 00:00:00 2001 From: Matteo <5571458+mtagliab@users.noreply.github.com> Date: Fri, 20 Sep 2019 15:45:05 +0200 Subject: [PATCH 2/3] Added test to check colon is correctly removed --- test/UriTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/UriTest.php b/test/UriTest.php index 16064bf15..42791dafc 100644 --- a/test/UriTest.php +++ b/test/UriTest.php @@ -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); + + } } From 1f4b6c770260b63c366ee62f362ba5d30068f6c1 Mon Sep 17 00:00:00 2001 From: Matteo <5571458+mtagliab@users.noreply.github.com> Date: Mon, 23 Sep 2019 08:47:38 +0200 Subject: [PATCH 3/3] Fix - removed double port assign --- src/Uri.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Uri.php b/src/Uri.php index 3e27270ea..d9bdcf842 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -312,7 +312,6 @@ public function parse($uri) $this->setPort((int) $port); } - $this->setPort((int) $port); $authority = substr($authority, 0, -$portLength); }