Skip to content

Commit 5599d72

Browse files
committed
fix: handling fragment
1 parent df5bf35 commit 5599d72

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

system/HTTP/SiteURI.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function __construct(
125125

126126
// Set routePath
127127
$parts = explode('?', $relativePath);
128+
$parts = explode('#', $parts[0]);
128129
$routePath = $parts[0];
129130
$this->setRoutePath($routePath);
130131
}

tests/system/HTTP/SiteURITest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ public function testConstructorRelativePathWithQuery()
5858
$this->assertSame('foo=1&bar=2', $uri->getQuery());
5959
}
6060

61+
public function testConstructorRelativePathWithFragment()
62+
{
63+
$config = new App();
64+
65+
$uri = new SiteURI($config, 'one/two#sec1');
66+
67+
$this->assertSame('http://example.com/index.php/one/two#sec1', (string) $uri);
68+
$this->assertSame('/index.php/one/two', $uri->getPath());
69+
$this->assertSame('', $uri->getQuery());
70+
$this->assertSame('sec1', $uri->getFragment());
71+
}
72+
73+
public function testConstructorRelativePathWithQueryAndFragment()
74+
{
75+
$config = new App();
76+
77+
$uri = new SiteURI($config, 'one/two?foo=1&bar=2#sec1');
78+
79+
$this->assertSame('http://example.com/index.php/one/two?foo=1&bar=2#sec1', (string) $uri);
80+
$this->assertSame('/index.php/one/two', $uri->getPath());
81+
$this->assertSame('foo=1&bar=2', $uri->getQuery());
82+
$this->assertSame('sec1', $uri->getFragment());
83+
}
84+
6185
public function testConstructorHost()
6286
{
6387
$config = new App();

0 commit comments

Comments
 (0)