purl
purl copied to clipboard
Purl can fail to parse the fragment
Purl tries to parse fragments, but does not check for errors. When it happens, the fragment is completely missing from the stringified URL:
$url = new Url('http://example.com/#hello:123');
echo (string) $url, "\n";
This script outputs this:
http://example.com/
The problem is that in Fragment.php, $this->data
is merged with the result of parse_url($this->fragment)
. If parse_url returns false, array_merge returns null, and $this->data is null:
https://github.com/jwage/purl/blob/87bb71167c17f64abc59d41123672100f4c8b616/src/Purl/Fragment.php#L112
Here is a fix that worked for me: https://github.com/arnaud-lb/purl/commit/67a6f618dff7b9c4ed8261378ea2a4730de76936
Hi, Thanks for creating the issue and investigating the problem. Could you send a pull request for this change?
I tried this fix but it doesn't seem to work. I am not sure how to fix this at the moment.