Bug #80665 [NEW]: DOMDocument object corruption during cloning
| From: | andrey at email dot dp dot ua | Date: | Mon, 25 Jan 2021 10:18:50 +0000 |
| Subject: | Bug #80665 [NEW]: DOMDocument object corruption during cloning | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-231744@lists.php.net to get a copy of this message | ||
From: andrey at email dot dp dot ua
Operating system: Debian Linux
PHP version: Irrelevant
Package: DOM XML related
Bug Type: Bug
Bug description:DOMDocument object corruption during cloning
Description:
------------
Description
------------
When DOMDocument is cloned, properties are cloned incorrectly.
saveHTML method of the cloned object provides different results as the
same method of original object.
saveHTML of the cloned object launched with additional documentElement
parameter provides result with symbols converted to numeric character
references. But saveHTML launched without parameters returns correct
result
Properties that are corrupted during cloning
---------------------------------------------
$DOMDocument->nodeType
if original object has nodeType XML_HTML_DOCUMENT_NODE, after cloning it
will be set to XML_DOCUMENT_NODE
$DOMDocument->baseURI
value is lost during cloning
$DOMDocument->version
if not set on original object will be set to 1.0
$DOMDocument->xmlVersion
if not set on original object will be set to 1.0
Methods that has different result on cloned object
-------------------------------------------------
"Carriage-return" symbols in original document correctly returned by
$DOMDocument->saveHTML() method, but replaced with on when used
$DOMDocument->saveHTML($DOMDocument->documentElement) on cloned object.
Test script:
---------------
<?php
$html = "<html><head><base
href='https://php.net'></head><body>\r</body></html>";
$dom = new DOMDocument();
$dom->loadHTML($html);
$arr = array(
'DOMDocument' => $dom,
'cloned by clone' => clone $dom,
'cloned by cloneNode' => $dom->cloneNode(true)
);
foreach ($arr as $descr=>$obj)
{
echo $descr.":\n";
echo "--------------------------\n";
echo "saveHTML:\n";
echo $obj->saveHTML()."\n\n";
echo "saveHTML via DOMDocument::documentElement:\n";
echo $obj->saveHTML($obj->documentElement)."\n\n";
echo "\$DOMDocument->nodeType = ".$obj->nodeType."\n";
echo "\$DOMDocument->baseURI = ".$obj->baseURI."\n";
echo "\$DOMDocument->version = ".$obj->version."\n";
echo "\$DOMDocument->xmlVersion = ".$obj->xmlVersion."\n\n\n";
}
Expected result:
----------------
[ three times ]
saveHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><base href="https://php.net"></head><body>
</body></html>
saveHTML(documentElement):
<html><head><base href="https://php.net"></head><body>
</body></html>
$DOMDocument->nodeType = 13
$DOMDocument->baseURI = https://php.net
$DOMDocument->version =
$DOMDocument->xmlVersion =
Actual result:
--------------
DOMDocument:
--------------------------
saveHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
</body></html>ase href="https://php.net"></head><body>
saveHTML(documentElement):
</body></html>ase href="https://php.net"></head><body>
$DOMDocument->nodeType = 13
$DOMDocument->baseURI = https://php.net
$DOMDocument->version =
$DOMDocument->xmlVersion =
cloned by clone:
--------------------------
saveHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
</body></html>ase href="https://php.net"></head><body>
saveHTML(documentElement):
<html><head><base
href="https://php.net"></head><body> </body></html>
$DOMDocument->nodeType = 9
$DOMDocument->baseURI =
$DOMDocument->version = 1.0
$DOMDocument->xmlVersion = 1.0
cloned by cloneNode:
--------------------------
saveHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
</body></html>ase href="https://php.net"></head><body>
saveHTML(documentElement):
<html><head><base
href="https://php.net"></head><body> </body></html>
$DOMDocument->nodeType = 9
$DOMDocument->baseURI =
$DOMDocument->version = 1.0
$DOMDocument->xmlVersion = 1.0
--
Edit bug report at https://bugs.php.net/bug.php?id=80665&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80665&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80665&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80665&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80665&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80665&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80665&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80665&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80665&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80665&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80665&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80665&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80665&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80665&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80665&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80665&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80665&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80665&r=mysqlcfg