php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40656 DOMDocument::load() urlencodes parts of an URI
Submitted: 2007-02-27 10:05 UTC Modified: 2007-02-28 14:49 UTC
From: bugs at php dot frankkleine dot de Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.1 OS: irrelevant
Private report: No CVE-ID: None
 [2007-02-27 10:05 UTC] bugs at php dot frankkleine dot de
Description:
------------
The DOMDocument::load() method does not support working with stream wrappers. It's an inconsistency within PHP, one would expect that this method works with stream wrappers as well just as other methods and functions do.

Reproduce code:
---------------
class MyStreamWrapper 
{
    protected $read   = false;
    protected $stream = '<?xml version="1.0" encoding="iso-8859-1"?><foo><bar id="1">hello world</bar></foo>';
    public function stream_open($path, $mode, $options, $opened_path) {return true; }
    public function stream_close() { }
    public function stream_read($count)
    {
        if (true == $this->read) { return ''; }
        $this->read = true;
        return $this->stream;
    }
    public function stream_eof() { return $this->read; }
    public function stream_stat() { return strlen($this->stream); }
    public function url_stat($path) { return strlen($this->stream); }
}
stream_wrapper_register('myStream', 'MyStreamWrapper');
$doc = DOMDocument::load('myStream://foo.xml');
var_dump($doc);

Expected result:
----------------
object(DOMDocument)#1 (0) { } 

Actual result:
--------------
Warning: DOMDocument::load() [function.DOMDocument-load]: I/O warning : failed to load external entity "myStream://foo" in DomDocument_load-StreamWrapper.php on line 43

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-27 11:22 UTC] rrichards@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

url_stat needs to return an array
 [2007-02-28 14:23 UTC] bugs at php dot frankkleine dot de
Thanks to your reply I found out what the real problem is. The DOMDocument::load() urlencodes parts of the URI used for the stream wrapper:
myStream://C:\master\bla.php?foo.xml
becomes
myStream://C:%5Cmaster%5Cbla.php?foo.xml"
To work properly, the stream wrapper class first has to look if the $path argument of stream_open() does exist, if not it has to do an urldecode() on the $path  and then check if the urldecoded $path exists. It is my expectation that the stream wrapper should get the correct $path from DOMDocument::load(), not an urlencoded one.
 [2007-02-28 14:49 UTC] rrichards@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

You have to use valid URIs (hence the "\" gets encoded).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 03:01:33 2024 UTC