purl icon indicating copy to clipboard operation
purl copied to clipboard

Purl can fail to parse the fragment

Open arnaud-lb opened this issue 6 years ago • 3 comments

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

arnaud-lb avatar Jun 11 '18 18:06 arnaud-lb

Here is a fix that worked for me: https://github.com/arnaud-lb/purl/commit/67a6f618dff7b9c4ed8261378ea2a4730de76936

arnaud-lb avatar Jun 11 '18 18:06 arnaud-lb

Hi, Thanks for creating the issue and investigating the problem. Could you send a pull request for this change?

jwage avatar Jun 11 '18 20:06 jwage

I tried this fix but it doesn't seem to work. I am not sure how to fix this at the moment.

jwage avatar Apr 11 '19 18:04 jwage