php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61469 simplexml_load_file() url encodes file names if they use a stream wrapper
Submitted: 2012-03-21 22:43 UTC Modified: 2012-03-23 12:33 UTC
From: saschagros at gmail dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.3.10 OS: Linux/Windows
Private report: No CVE-ID: None
 [2012-03-21 22:43 UTC] saschagros at gmail dot com
Description:
------------
Drupal uses custom stream wrappers for accessing files.

Given the file name "$imported_file = 'temporary://translated file.xlf'", the following does not work:

$xml = simplexml_load_file($imported_file);

It results in the following warning:
simplexml_load_file(): I/O warning : failed to load external entity "temporary://translated%20file.xlf"

However, this works just fine:

$xml_string = file_get_contents($imported_file);
$xml = simplexml_load_string($xml_string);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-22 07:35 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2012-03-22 07:35 UTC] cataphract@php.net
Looks right. URIs cannot contain spaces. See RFC 3986.
 [2012-03-22 14:00 UTC] saschagros at gmail dot com
temporary is not a remote URI that points to a HTTP resource. This is a local file.

If the space needs to be encoded internally, fine. But it has to be possible to access a file with a space in it using a stream wrapper? After all, file_get_contents() works just fine.
 [2012-03-22 15:31 UTC] berdir@php.net
-Status: Not a bug +Status: Open
 [2012-03-23 12:33 UTC] cataphract@php.net
The fact file_get_contents "works just fine" is irrelevant. There's a difference between what 1) URIs you're willing to accept and 2) which URIs you generate. Only the latter must be well-formed. And in fact libxml generates correct URIs. The bug is in your custom stream wrapper that doesn't parse the path in URI correctly and just takes it as is.
 [2012-03-23 12:33 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2012-03-23 12:33 UTC] cataphract@php.net
.
 [2014-10-09 13:50 UTC] hanskrentel at yahoo dot de
@cataphract@php.net: If the stream wrapper that doesn't parse the path in URI correctly is not a self made one but one in PHP core (e.g. file://) and you would follow the same argumentation of yours, could you then please take a look in bug #63769.

I have problems to bring libxml together with PHP when libxml based libraries want to use correct their URIs and then it's the PHP file stream wrapper "that doesn't parse the path in URI correctly and just takes it as is."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC