Doc #55374 [Opn->Ver]: DOMDocument::LoadHTMLFile fails with %xx sequences in filename.

From: Date: Thu, 08 Apr 2021 14:35:10 +0000
Subject: Doc #55374 [Opn->Ver]: DOMDocument::LoadHTMLFile fails with %xx sequences in filename.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18699@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55374&edit=1

 ID:                 55374
 Updated by:         cmb@php.net
 Reported by:        keithm at aoeex dot com
 Summary:            DOMDocument::LoadHTMLFile fails with %xx sequences
                     in filename.
-Status:             Open
+Status:             Verified
 Type:               Documentation Problem
-Package:            DOM XML related
+Package:            XML related
 Operating System:   Linux
 PHP Version:        5.4.0alpha3
 Block user comment: N
 Private report:     N

 New Comment:

Hmm, this looks like a bug to me.  At least the behavior is
inconsistent with the general file functions, and it is not
directly related to libxml2.  Actually, the bug fix appears to be
trivial:


 ext/libxml/libxml.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index fc194770e1..68fd0e37c7 100644
--- a/ext/libxml/libxml.c
+++ b/ext/libxml/libxml.c
@@ -305,7 +305,7 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
 
 
 	uri = xmlParseURI(filename);
-	if (uri && (uri->scheme == NULL ||
+	if (uri && (
 			(xmlStrncmp(BAD_CAST uri->scheme, BAD_CAST "file", 4) == 0))) {
 		resolved_path = xmlURIUnescapeString(filename, 0, NULL);
 		isescaped = 1;


But given the long standing behavior, and the BC break, this
shouldn't be fixed for any stable version (and probably only in a
new major version), so yes, the behavior should be documented.

And to be clear: this affects all XML extensions which use
libxml2, not only DOM.


Previous Comments:
------------------------------------------------------------------------
[2011-08-06 06:37:07] keithm at aoeex dot com

Description:
------------
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'

---------------------------------------8<---------------------------------------
<html>
 <head>
  <title></title>
 </head>
 <body>
 </body>
</html>
---------------------------------------8<---------------------------------------


contents of 'test.php'
---------------------------------------8<---------------------------------------
<?php

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

$doc = new DOMDocument();
$doc->loadHTMLFile($file);
var_dump($doc->getElementsByTagName('body')->length);

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

$doc2 = new DOMDocument();
$doc2->loadHTMLFile(urlencode($file));
var_dump($doc2->getElementsByTagName('body')->length);
---------------------------------------8<---------------------------------------


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.



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



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


Thread (1 message)

  • cmb@php.net
  • Unknown Message
    • cmb@php.net
« previous php.doc.bugs (#18699) next »