Bug #70934 [NEW]: DOMDocument return wrong tree by tag in script tag
| From: | sashott at abv dot bg | Date: | Wed, 18 Nov 2015 10:54:43 +0000 |
| Subject: | Bug #70934 [NEW]: DOMDocument return wrong tree by tag in script tag | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-197317@lists.php.net to get a copy of this message | ||
From: sashott at abv dot bg
Operating system: Linux
PHP version: 5.5Git-2015-11-18 (snap)
Package: DOM XML related
Bug Type: Bug
Bug description:DOMDocument return wrong tree by tag in script tag
Description:
------------
DOMDocument return wrong tree by tag in variable in script tag. As
example in DIV, a closing tag DIV written in script tag (in text
variable), close the previous DIV.
Test script:
---------------
<?php
$html_content='<!DOCTYPE html>
<html>
<body>
<div id="something">
<script>
var somevar=\'<div></div>\';
</script>
<div></div>
<div></div>
</div>
</body>
</html>
';
$oldSetting=libxml_use_internal_errors(true);
libxml_clear_errors();
$html=new DOMDocument();
$html->loadHtml($html_content);
$node=$html->getElementById('something');
echo "<pre>";
foreach($node->childNodes as $child_node){
echo $child_node->nodeName."\n";
}
echo "</pre>";
libxml_clear_errors();
libxml_use_internal_errors($oldSetting);
//Result:
//#text
//script
//Error appear from: var somevar=\'<div></div>\';
?>
Expected result:
----------------
script
div
div
//Can have some #text between them.
Actual result:
--------------
#text
script
--
Edit bug report at https://bugs.php.net/bug.php?id=70934&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70934&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70934&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70934&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70934&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70934&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70934&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70934&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70934&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70934&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70934&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70934&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70934&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70934&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70934&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70934&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70934&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70934&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70934&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70934&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70934&r=mysqlcfg