diff --git a/src/Purl/Fragment.php b/src/Purl/Fragment.php index 96706b0..6b84362 100644 --- a/src/Purl/Fragment.php +++ b/src/Purl/Fragment.php @@ -7,6 +7,8 @@ use function array_merge; use function parse_url; use function sprintf; +use function strpos; +use function substr; /** * Fragment represents the part of a Url after the hashmark (#). @@ -109,6 +111,10 @@ public function __toString() : string protected function doInitialize() : void { if ($this->fragment !== null) { + $pos = strpos($this->fragment, ':', 1); + if ($pos !== false) { + $this->fragment = substr($this->fragment, 0, $pos); + } $data = parse_url($this->fragment); if ($data === false) { $data = ['path' => $this->fragment]; diff --git a/tests/Purl/Test/UrlTest.php b/tests/Purl/Test/UrlTest.php index 23ee2d0..212203a 100644 --- a/tests/Purl/Test/UrlTest.php +++ b/tests/Purl/Test/UrlTest.php @@ -365,7 +365,7 @@ public function testRelativeUrl() : void // test fragment with colon $url = new Url('http://example.com/#hello:123'); - $this->assertEquals('http://example.com/', (string) $url); + $this->assertEquals('http://example.com/#hello', (string) $url); } }