diff --git a/src/Purl/Fragment.php b/src/Purl/Fragment.php index 96706b0..e0665ee 100644 --- a/src/Purl/Fragment.php +++ b/src/Purl/Fragment.php @@ -109,6 +109,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); } }