|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62844 parse_url() does not recognize //
Submitted: 2012-08-17 09:22 UTC Modified: 2012-08-20 05:21 UTC
From: phpqa at sebastianmendel dot de Assigned: stas (profile)
Status: Closed Package: URL related
PHP Version: 5.4.6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: phpqa at sebastianmendel dot de
New email:
PHP Version: OS:


 [2012-08-17 09:22 UTC] phpqa at sebastianmendel dot de
parse_url() does not recognize '//' as scheme to host separator and therefor does 
not recognize as host in URL "//"

Test script:

Expected result:
array(1) {
  'host' =>
  string(11) ""

Actual result:
array(1) {
  'path' =>
  string(14) "//"


parse_url_relative_scheme2 (last revision 2012-08-19 23:31 UTC by ajf at ajf dot me)
parse_url_relative_scheme (last revision 2012-08-19 23:10 UTC by ajf at ajf dot me)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-17 09:59 UTC] phpqa at sebastianmendel dot de
even if doc says "This function doesn't work with relative URLs." it also says: 
"Partial URLs are also accepted, parse_url() tries its best to parse them 

and it parses relative URLs like /path/file.html?var=1&foo=bar#123 correctly
 [2012-08-19 23:33 UTC] ajf at ajf dot me
Added patch and made pull request:
 [2012-08-20 05:21 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

 [2012-08-20 05:21 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2013-10-22 16:44 UTC] hanskrentel at yahoo dot de
There is a problem when having @ before the (empty) hostname, the "try best as possible" is gone then since 5.4.7 (when this 62844 fix was introduced):

echo print_r(parse_url('//site@/path/to/file.css?query'));

not parsing any path nor other parts any longer - it did before. the fix has somewhat broken this.

Also why do you introduce a backwards incompatible change in a minor revision?
 [2013-10-22 18:45 UTC] ajf at ajf dot me

The change was not, so far as we knew, backwards-incompatible. It broke no existing test cases and introduced a new one.

It says "Partial URLs are also accepted, parse_url() tries its best to parse them correctly." in the documentation. This is correct, and this patch helped that, as it fixed a partial URL case which wasn't working.

It's unfortunate that the case you are showing was broken, however I do not believe that is a valid URI (please point me to the section in the RFC disagreeing if I'm wrong), and while parse_url() will "try its best" to parse partial URLs, it can't reasonably be expected to "try its best" to parse malformed URLs.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 29 21:01:25 2023 UTC