diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index 110d189e9d12..958c503a5cdd 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -125,6 +125,7 @@ public function __construct( // Set routePath $parts = explode('?', $relativePath); + $parts = explode('#', $parts[0]); $routePath = $parts[0]; $this->setRoutePath($routePath); } diff --git a/tests/system/HTTP/SiteURITest.php b/tests/system/HTTP/SiteURITest.php index 11153fb9b7fd..e8c2f4365b9c 100644 --- a/tests/system/HTTP/SiteURITest.php +++ b/tests/system/HTTP/SiteURITest.php @@ -58,6 +58,30 @@ public function testConstructorRelativePathWithQuery() $this->assertSame('foo=1&bar=2', $uri->getQuery()); } + public function testConstructorRelativePathWithFragment() + { + $config = new App(); + + $uri = new SiteURI($config, 'one/two#sec1'); + + $this->assertSame('http://example.com/index.php/one/two#sec1', (string) $uri); + $this->assertSame('/index.php/one/two', $uri->getPath()); + $this->assertSame('', $uri->getQuery()); + $this->assertSame('sec1', $uri->getFragment()); + } + + public function testConstructorRelativePathWithQueryAndFragment() + { + $config = new App(); + + $uri = new SiteURI($config, 'one/two?foo=1&bar=2#sec1'); + + $this->assertSame('http://example.com/index.php/one/two?foo=1&bar=2#sec1', (string) $uri); + $this->assertSame('/index.php/one/two', $uri->getPath()); + $this->assertSame('foo=1&bar=2', $uri->getQuery()); + $this->assertSame('sec1', $uri->getFragment()); + } + public function testConstructorHost() { $config = new App();