Bug #54429 [NEW]: domDocument::loadHTML adds extra CDATA tags causing script errors.
| From: | ken at smallboxcms dot com | Date: | Thu, 31 Mar 2011 04:23:33 +0000 |
| Subject: | Bug #54429 [NEW]: domDocument::loadHTML adds extra CDATA tags causing script errors. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-159864@lists.php.net to get a copy of this message | ||
From:
Operating system: Centos 5.5
PHP version: 5.3.6
Package: DOM XML related
Bug Type: Bug
Bug description:domDocument::loadHTML adds extra CDATA tags causing script errors.
Description:
------------
This one has annoyed me for a long time. When you load HTML useing loadHTML
you get extra CDATA tags on the script tags causing browser errors. This
does not happen when loadXML is used.
Test script:
---------------
<?php
$foo = '
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
alert("foo bar");
//]]>
</script>
</body>
</html>
';
$dom = new domDocument('1,0', 'utf-8');
$dom->loadHTML($foo);
echo $dom->saveXML();
?>
Expected result:
----------------
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title/></head><body>
<script type="text/javascript">
//<![CDATA[
alert("foo bar");
//]]>
</script></body></html>
Actual result:
--------------
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title/></head><body>
<script type="text/javascript"><![CDATA[
//<![CDATA[
alert("foo bar");
//]]]]><![CDATA[>
]]></script></body></html>
--
Edit bug report at http://bugs.php.net/bug.php?id=54429&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54429&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54429&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54429&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=54429&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54429&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=54429&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=54429&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=54429&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=54429&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=54429&r=support
Expected behavior: http://bugs.php.net/fix.php?id=54429&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=54429&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=54429&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=54429&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54429&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54429&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=54429&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=54429&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=54429&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=54429&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=54429&r=mysqlcfg