|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55374 DOMDocument::LoadHTMLFile fails with %xx sequences in filename.
Submitted: 2011-08-06 06:37 UTC Modified: 2013-12-02 16:34 UTC
Avg. Score:4.4 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:2 (28.6%)
From: keithm at aoeex dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 5.4.0alpha3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
37 - 37 = ?
Subscribe to this entry?

 [2011-08-06 06:37 UTC] keithm at aoeex dot com
DOMDocument::LoadHTMLFile appears to urldecode it's argument, which causes 
problems when attempting to load a file containing a %xx sequence.

This issue was brought up on ##php in freenode when someone was attempting to load 
a file named 'Linux_Files%2Fetc%2Fbash.bashrc.html'.  Suggested work around was to 
use LoadHTML + file_get_contents instead.

There was a small debate over whether this is a bug, or just a documentation 
problem (perhaps LoadHTMLFile expects a URL).

DOMDocument::Load() is also affected.

Test script:
Contents of 'Linux_Files%2Fetc%2Fbash.bashrc.html'


contents of 'test.php'

$file = 'Linux_Files%2Fetc%2Fbash.bashrc.html';

$doc = new DOMDocument();

echo str_repeat('-', 80), "\r\n";

$doc2 = new DOMDocument();

Expected result:
Expect the ->loadHTMLFile($file) to succeed and the -
>loadHTMLFile(urlencode($file)) to fail with a file-not-found type error.

Actual result:
->loadHTMLFile($file) failes with errors:

PHP Warning:  DOMDocument::loadHTMLFile(): I/O warning : failed to load external 
entity "Linux_Files%2Fetc%2Fbash.bashrc.html" in /home/kicken/test.php on line 6

Warning: DOMDocument::loadHTMLFile(): I/O warning : failed to load external entity 
"Linux_Files%2Fetc%2Fbash.bashrc.html" in /home/kicken/test.php on line 6

->loadHTMLFile(urlencode($file)) succeeds.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-02 16:34 UTC]
-Type: Bug +Type: Documentation Problem
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Sep 24 15:01:23 2020 UTC