Skip to content

Commit 5f7906e

Browse files
authored
Merge pull request #2824 from Instrye/patch-setPath
fix. URI path is empty
2 parents 3490e53 + 348b352 commit 5f7906e

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

system/HTTP/URI.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff 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

tests/system/HTTP/URITest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)