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

Fix issue #66 #67

wants to merge 3 commits into from

Conversation

peter279k
Copy link
Contributor

Changed log

Try to fix issue #66.

@jwage
Copy link
Owner

jwage commented Jun 24, 2018

Can you add a test to cover this scenario?

@peter279k
Copy link
Contributor Author

Hi @jwage, thank you for your reply. I've added the mapped unit test for this issue.

@jwage
Copy link
Owner

jwage commented Jun 24, 2018

I don't understand what this is fixing. The hashbang is removed?


// 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.

@@ -109,7 +109,16 @@ public function __toString() : string
protected function doInitialize() : void
{
if ($this->fragment !== null) {
$this->data = array_merge($this->data, parse_url($this->fragment));
$pos = strpos($this->fragment, ':', 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jwage, I use the strpos function to get the first position of the colon character.
And sub the string with colon then return the current url with the valid fragment.

Copy link
Owner

Choose a reason for hiding this comment

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

I think we misunderstood each other. It should maintain the whole hashbang. i.e. #hello:123

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. The hash bang value is the #hello:123.
Perhaps we can rebuild the fragment value after using the parse_url function.

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.

Yes. We would need to parse out the hashbang manually instead of relying on parse_url since it can't handle it when it has a colon on it.

@@ -109,7 +111,17 @@ public function __toString() : string
protected function doInitialize() : void
{
if ($this->fragment !== null) {
$this->data = array_merge($this->data, parse_url($this->fragment));
$pos = strpos($this->fragment, ':', 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is my approach:

  • Detect the hash bang whether it's with the colon.
  • Rebuild the hash bang with the colon after using the parse_url function.

Copy link
Contributor

Choose a reason for hiding this comment

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

@peter279k: Are we sure that this is the only case that would cause parse_str to fail ? Why not just use parse_str right away, and fallback to $data = ['path' => $this->fragment] if it fails ?

It would make less assumptions about how parse_str works now and in the future. This would make this code more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants