-
Notifications
You must be signed in to change notification settings - Fork 123
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
base: master
Are you sure you want to change the base?
Fix issue #66 #67
Conversation
Can you add a test to cover this scenario? |
Hi @jwage, thank you for your reply. I've added the mapped unit test for this issue. |
I don't understand what this is fixing. The hashbang is removed? |
tests/Purl/Test/UrlTest.php
Outdated
|
||
// test fragment with colon | ||
$url = new Url('http://example.com/#hello:123'); | ||
$this->assertEquals('http://example.com/', (string) $url); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/Purl/Fragment.php
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Changed log
Try to fix issue #66.