This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments