note 118134 deleted from function.parse-url by cmb
| From: | cmb@php.net | Date: | Sun, 06 Oct 2019 08:19:25 +0000 |
| Subject: | note 118134 deleted from function.parse-url by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212510@lists.php.net to get a copy of this message | ||
Note Submitter: mostafa at alfehrest dot org
----
This function will attempt to parse relative URLs but relaying on it can produce unexpected behavior
that can cause some hard to track bugs. (The following results are obtained from PHP 5.5.19)
Attempting to parse a url like this
http://example.com/entities/GOA:98/?search=8989157d1f22
Correctly produces
<?php
array (
'scheme' => 'http',
'host' => 'example.com',
'path' => '/entities/GOA:98/',
'query' => 'search=8989157d1f22',
);
?>
However, Attempting to parse the relative URL
entities/GOA:98/?search=8989157d1f22
<?php
array (
'host' => 'entities',
'port' => 98,
'path' => '/GOA:98/',
'query' => 'search=8989157d1f22',
)
?>
If I change :98 to :A98 parse_url parses the URL correctly as
<?php
array (
'path' => 'entities/GOA:A98/',
'query' => 'search=8989157d1f22',
)
?>
Bottom line, Avoid using parse_url for relative urls unless you have tested the expected input and
you know parse_url will handle them well.