php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33138 parse_url() wrongly handles relative URIs with ':'
Submitted: 2005-05-25 15:34 UTC Modified: 2005-05-27 15:28 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: moriyoshi@php.net Assigned:
Status: Not a bug Package: URL related
PHP Version: 4.3.11 OS: Irrelevant
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: moriyoshi@php.net
New email:
PHP Version: OS:

 

 [2005-05-25 15:34 UTC] moriyoshi@php.net
Description:
------------
parse_url() cannot handle relative URIs (ones without 
schemes) that contains ':' within the queries.

Reproduce code:
---------------
var_dump(parse_url('/a/b/c'));
var_dump(parse_url('/a/b/c?d:'));
var_dump(parse_url('/a/b/c?d:e'));


Expected result:
----------------
array(1) {
  ["path"]=>
  string(6) "/a/b/c"
}
array(2) {
  ["path"]=>
  string(6) "/a/b/c"
  ["query"]=>
  string(6) "d:"
}
array(2) {
  ["path"]=>
  string(6) "/a/b/c"
  ["query"]=>
  string(6) "d:e"
}


Actual result:
--------------
array(1) {
  ["path"]=>
  string(6) "/a/b/c"
}

Warning: parse_url(/a/b/c?d:): Unable to parse url in 
Command line code on line 2
bool(false)
array(2) {
  ["scheme"]=>
  string(8) "/a/b/c?d"
  ["path"]=>
  string(1) "e"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-25 17:10 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

A URL without a schema default to a local file, a locale file cannot have GET parameters. Hence the error, there is no bug here.
 [2005-05-25 19:03 UTC] moriyoshi@php.net
Is there any specification that suggests relative URI's 
point to local resources by default? Otherwise 
parse_url() is not supposed to conform to the RFC.
 [2005-05-25 20:49 UTC] iliaa@php.net
There is no requirment to support relative URL. All of the URLs with which URL RFC deals have a sheme or equivalent.
 [2005-05-25 21:02 UTC] moriyoshi@php.net
Wouldn't it be handy if the *URI* syntax (or RFC1808 at 
least) is supported in addition to the URL syntax?

As it can already handle relative pathes just partly at 
the moment, there shouldn't be no BC problem.
 [2005-05-25 23:38 UTC] iliaa@php.net
At the moment the code follows the RFC 1738 with some additions, which is the URL specification. As far as adding partial URL support, please consider the following; c?d:e, c?d:, etc... are all valid file names, at least on *NIX.

The only bug I see here is that we "break" the spec and allow scheme to contain non-valid chars such as / and ?. In all of the provided examples the path should contain the entire string.
 [2005-05-26 05:57 UTC] iliaa@php.net
I've added scheme validation to the code, which coincidentally made your examples work as expected :-)
 [2005-05-27 15:28 UTC] moriyoshi@php.net
Okay, I'm gonna check it out. Thank you for taking care 
of this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC