diff --git a/src/Purl/Fragment.php b/src/Purl/Fragment.php index 96706b0..ccd9d11 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,8 +111,13 @@ public function __toString() : string protected function doInitialize() : void { if ($this->fragment !== null) { + $pos = strpos($this->fragment, ':', 1); + $colon = ''; + if ($pos !== false) { + $colon = substr($this->fragment, $pos); + } $data = parse_url($this->fragment); - if ($data === false) { + if ($colon !== '') { $data = ['path' => $this->fragment]; } diff --git a/tests/Purl/Test/UrlTest.php b/tests/Purl/Test/UrlTest.php index 23ee2d0..6fe671b 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:123', (string) $url); } }