php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43721 parse_url does not handle "protocol relative" URLs
Submitted: 2007-12-31 18:10 UTC Modified: 2007-12-31 21:27 UTC
From: phpbugs at thequod dot de Assigned:
Status: Not a bug Package: URL related
PHP Version: 5.2.5 OS: Ubuntu Linux
Private report: No CVE-ID: None
 [2007-12-31 18:10 UTC] phpbugs at thequod dot de
Description:
------------
parse_url does not parse "protocol relative" URLs correctly.

"protocol relative" URLs start with to slashes, leaving the "proto:" 
part out.

parse_url should parse them like a "http://" url, but leave 
the "protocol" key unset, as far as I can see.

See RFC3986.

Reproduce code:
---------------
$ php -r '$p = parse_url("//example.com/bar"); var_dump($p);'


Expected result:
----------------
array(2) {
  ["host"]=>
  string(11) "example.com"
  ["path"]=>
  string(17) "/bar"
}


Actual result:
--------------
array(1) {
  ["path"]=>
  string(17) "//example.com/bar"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-31 21:27 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's expected, because unless a protocol is specified, it assumes 
file://
 [2013-01-24 09:13 UTC] victor dot sollerhed at gmail dot com
I think this actually is a bug. Could this please be re-opened?

"A relative URL without a scheme (http: or https:) is valid, per RFC 3986: 
"Uniform Resource Identifier (URI): Generic Syntax", Section 4.2. If a client 
chokes on it, then it's the client's fault because they're not 
complying with the URI syntax specified in the RFC."

Please see:

http://stackoverflow.com/questions/550038/is-it-valid-to-replace-http-with-in-a-
script-src-http

http://stackoverflow.com/questions/3583103/network-path-reference-uri-scheme-
relative-urls/
 [2013-09-22 17:30 UTC] yastrakhan at wikimedia dot org
I also think this is a very unintuitive behavior - protocol-relative URLs are very common, while the file:// has very limited and archaic use. parse_url() should behave very similar to modern browsers.
 [2014-01-10 11:10 UTC] bluemoehre at gmx dot de
Today i had to build a workaround for that. This behaviour is unexpected and should be changed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC