Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #66 #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Purl/Fragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ public function __toString() : string
protected function doInitialize() : void
{
if ($this->fragment !== null) {
$this->data = array_merge($this->data, parse_url($this->fragment));
$data = parse_url($this->fragment);
if ($data === false) {
$data = ['path' => $this->fragment];
}

$this->data = array_merge($this->data, $data);
}

foreach ($this->data as $key => $value) {
Expand Down
4 changes: 4 additions & 0 deletions tests/Purl/Test/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ public function testRelativeUrl() : void
$url = new Url('/events');
$url->query->set('param1', 'value1');
$this->assertEquals('/events?param1=value1', (string) $url);

// test fragment with colon
$url = new Url('http://example.com/#hello:123');
$this->assertEquals('http://example.com/', (string) $url);
Copy link
Contributor Author

@peter279k peter279k Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwage, yes. It's fixed that issue. Please see more details about that.
It has removed the hash bang.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel right to me. It shouldn't just silently remove it from the URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this improvement?
I think we can fetch this hash bang and store another key in Url instance.

What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are hashbangs technically allowed to have a colon in them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that hash bang with colon is not the standard.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I am not sure if there is anything to fix here. Dropping the hashbang value entirely is not a good fix. I would maybe accept an enhancement to allow the hashbang with the colon like you described but that would be a more involved fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the approach:

  • parse the url.
  • get the fragment.
  • validate the fragment whether it's with the colon.

What do you think? Thanks.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can give it a try.

}
}

Expand Down