ID:               47070
 Updated by:       j...@php.net
 Reported By:      darrel dot opry at gmail dot com
-Status:           Bogus
+Status:           Open
-Bug Type:         Streams related
+Bug Type:         Feature/Change Request
 Operating System: Ubuntu 8.10
 PHP Version:      5.2.8
 New Comment:

Reclassified.


Previous Comments:
------------------------------------------------------------------------

[2009-01-15 16:25:37] darrel dot opry at gmail dot com

a note regarding backwards compatibility. This change shouldn't 
interfere with existing user defined stream wrappers, since they 
would not be called with if they used without the authority section 
currently.

------------------------------------------------------------------------

[2009-01-15 16:14:16] darrel dot opry at gmail dot com

I did RTFM. As a developer and user of PHP I disagree with your 
assertion. The use and parsing of the URL schema for streams is not 
the same as that of parse_url which is recommended for parsing 
incoming paths.

The documentation specifically uses the wording URL in many places, 
right to the point of having a setting for allow_url_fopen. 

The issue with the current approach is that it does not recognize 
legally delimited scheme's properly, and pass them to the underlying 
stream wrapper. It seems to make the invalid assumption that :// or 
// is the scheme delimiter when it is in fact :. It's a minor parsing 
issue that could probably be corrected by an experienced C developer 
in under 20 minutes.

Why is this an issue you may ask... 

parse_url properly parses the scheme, user, password, host, port, and 
path. 

If I want to use parse_url within my stream wrapper I have to 
concatenate the host and path elements if I use a URL in the form of 
file://path/to/file.txt or I have to use a url in the form of 
file://localhost/path/to/file.txt if I want to avoid this 
concatenation.

A secondary impact, if I'm storing URLs to resources in the database 
I now have to store the authority section as well. This is suboptimal 
for me as a application developer as the number of resources I'm 
storing references to increases. 

So maybe you should go RYOFM, before dismissing something out of hand 
just because it references and RFC without thinking of the 
implications.

Basically I think most developers really want their stream wrapper 
called if scheme: is properly designated, so they can write standards 
compliant code.

------------------------------------------------------------------------

[2009-01-15 15:26:34] j...@php.net

RTFM: http://www.php.net/fopen  (look for explanation what PHP expects
the filename parameter to look like...you can put as many RFCs here, but
it's never said anywhere that fopen() expects some RFCs style scheme..
:)

------------------------------------------------------------------------

[2009-01-12 03:01:10] darrel dot opry at gmail dot com

Description:
------------
php_stream_locate_url_wrapper fails without authority section.

If a URL is not in the Common Internet Scheme Syntax
(scheme://<<user>:<pass>@>host<:port>/url-path) the scheme is not be
located properly. So URLs of scheme:relative/path and
scheme:/absolute/path will not be handled by the registered user defined
stream wrapper.

see http://www.ietf.org/rfc/rfc1738.txt for URL specific syntax.

see section 3 of
http://labs.apache.org/webarch/uri/rfc/rfc3986.html#intro for URI
syntax.

Reproduce code:
---------------
<?php

class wrapper {
  function stream_open() {
    print_r(func_get_args());
    return TRUE;
  }
}

stream_wrapper_register('public', 'wrapper');

fopen('public:path/file.txt', 'r+');
fopen('public:/path/file.txt', 'r+');
fopen('public://path/file.txt', 'r+');


Expected result:
----------------
I expect wrapper::stream_open to be called and fopen to print_r the
function arguments.

Array
(
    [0] => public:path/file.txt
    [1] => r+
    [2] => 4
    [3] => 
)
Array
(
    [0] => public:/path/file.txt
    [1] => r+
    [2] => 4
    [3] => 
)
Array
(
    [0] => public://path/file.txt
    [1] => r+
    [2] => 4
    [3] => 
)

Actual result:
--------------
Warning: fopen(public:path/file.txt): failed to open stream: No such
file or directory in
/home/dopry/public_html/drupal-media/sites/default/modules/media/resource/test.php
on line 13

Warning: fopen(public:/path/file.txt): failed to open stream: No such
file or directory in
/home/dopry/public_html/drupal-media/sites/default/modules/media/resource/test.php
on line 14
Array
(
    [0] => public://path/file.txt
    [1] => r+
    [2] => 4
    [3] => 
)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47070&edit=1

Reply via email to