From a1b7c13107bc701c897801566bbe249334cac856 Mon Sep 17 00:00:00 2001 From: peter279k Date: Tue, 26 Jun 2018 02:40:13 +0800 Subject: [PATCH] Using strpos to remove colon character --- src/Purl/Fragment.php | 6 ++++++ tests/Purl/Test/UrlTest.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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); } }