Skip to content

Commit

Permalink
Using strpos to remove colon character
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Jun 25, 2018
1 parent 916a8e1 commit a1b7c13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Purl/Fragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (#).
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tests/Purl/Test/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit a1b7c13

Please sign in to comment.