File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -710,7 +710,9 @@ public function setPath(string $path)
710710 {
711711 $ this ->path = $ this ->filterPath ($ path );
712712
713- $ this ->segments = explode ('/ ' , $ this ->path );
713+ $ tempPath = trim ($ this ->path , '/ ' );
714+
715+ $ this ->segments = ($ tempPath === '' ) ? [] : explode ('/ ' , $ tempPath );
714716
715717 return $ this ;
716718 }
@@ -726,7 +728,9 @@ public function refreshPath()
726728 {
727729 $ this ->path = $ this ->filterPath (implode ('/ ' , $ this ->segments ));
728730
729- $ this ->segments = explode ('/ ' , $ this ->path );
731+ $ tempPath = trim ($ this ->path , '/ ' );
732+
733+ $ this ->segments = ($ tempPath === '' ) ? [] : explode ('/ ' , $ tempPath );
730734
731735 return $ this ;
732736 }
@@ -960,7 +964,9 @@ protected function applyParts(array $parts)
960964 // Populate our segments array
961965 if (isset ($ parts ['path ' ]) && $ parts ['path ' ] !== '' )
962966 {
963- $ this ->segments = explode ('/ ' , trim ($ parts ['path ' ], '/ ' ));
967+ $ tempPath = trim ($ parts ['path ' ], '/ ' );
968+
969+ $ this ->segments = ($ tempPath === '' ) ? [] : explode ('/ ' , $ tempPath );
964970 }
965971 }
966972
Original file line number Diff line number Diff line change @@ -848,4 +848,12 @@ public function testZeroAsURIPath()
848848 $ this ->assertEquals ('/0 ' , $ uri ->getPath ());
849849 }
850850
851+ public function testEmptyURIPath ()
852+ {
853+ $ url = 'http://example.com/ ' ;
854+ $ uri = new URI ($ url );
855+ $ this ->assertEquals ([], $ uri ->getSegments ());
856+ $ this ->assertEquals (0 , $ uri ->getTotalSegments ());
857+ }
858+
851859}
You can’t perform that action at this time.
0 commit comments