|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70942 parse_url for url without port and scheme, but with port-like string in url
Submitted: 2015-11-19 15:48 UTC Modified: 2021-04-21 12:28 UTC
Avg. Score:4.0 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (40.0%)
From: taco at procurios dot nl Assigned: cmb (profile)
Status: Not a bug Package: URL related
PHP Version: 5.6.15 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: taco at procurios dot nl
New email:
PHP Version: OS:


 [2015-11-19 15:48 UTC] taco at procurios dot nl
When a URL without a scheme and port, but with a port-like string (e.g. is passed to parse_url(), a port number is returned. This wasn't the case in, at least, PHP 5.6.6 ( seems to crash on this code...).

I'm guessing this commit introduced this issue:

Test script:

Expected result:



array(2) {
  string(11) ""
  string(9) "/foo:1234"

Actual result:
array(3) {
  string(11) ""
  string(9) "/foo:1234"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-20 09:25 UTC] taco at procurios dot nl
The commit I've mentioned does not introduce this issue. Afaik, this issue is much older, but was 'masked' by bug #68917. After this bug was fixed ( parse_url no longer returned false for URLs without a scheme, but with a colon.

parse_url assumes that the colon character can only be used for the port subcomponent of a URI, but it is allowed in the path component too (see: The parser should look for a colon character, but not after the first single slash in a URL, anything after that slash is part of the path, query or fragment.
 [2015-11-20 14:46 UTC]
-Assigned To: +Assigned To: datibbaw
 [2015-11-20 14:46 UTC]
@datibbaw, could you have a look into this one? thanks
 [2016-08-17 09:50 UTC] driezasson at icloud dot com
Even a URL with a port, but without a scheme doesn’t get parsed. E.g.: '//'.

Expected result:
['host' => '', 'port' => 80]

Actual result:
 [2017-10-24 07:15 UTC]
-Status: Assigned +Status: Open -Assigned To: datibbaw +Assigned To:
 [2021-04-21 12:28 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-04-21 12:28 UTC]
The problem is that parse_url() is so broken for partial URLs,
that whenever you fix something related to this, you likely
introduce a regression.  Thus, it's likely best to introduce a new
function with sane parsing conforming to RFC 3986.  This would
require the RFC process[1], though.

Anyhow, it is already documented[2] that

| Partial URLs are also accepted, parse_url() tries its best to
| parse them correctly.

So this is not a bug.

[1] <>
[2] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 23:01:29 2024 UTC