Bug #74241 [Opn->Nab]: DomDocument::loadHTML ignores LIBXML_NOCDATA
| From: | requinix@php.net | Date: | Mon, 13 Mar 2017 10:57:29 +0000 |
| Subject: | Bug #74241 [Opn->Nab]: DomDocument::loadHTML ignores LIBXML_NOCDATA | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207811@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74241&edit=1
ID: 74241
Updated by: requinix@php.net
Reported by: tom at r dot je
Summary: DomDocument::loadHTML ignores LIBXML_NOCDATA
-Status: Open
+Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: Linux
PHP Version: 7.1.2
Block user comment: N
Private report: N
New Comment:
LIBXML_NOCDATA, which matters at load time and not save time, is not respected because CDATA tags
make no sense to have in HTML.
Loading as HTML but saving as XML, or vice versa, is incorrect: either the content is HTML or it is
XML. If you want to deal with HTML fragments without the DTD and implied <html> elements then
use the LIBXML_HTML_NODEFDTD and LIBXML_HTML_NOIMPLIED options with loadHTML().
https://3v4l.org/8MnED
Previous Comments:
------------------------------------------------------------------------
[2017-03-13 10:42:23] tom at r dot je
Description:
------------
Using PHP 7.1 with Libxml version 2.9.4 DomDocument::loadHTML ignores LIBXML_NOCDATA.
Test script:
---------------
$doc = new \DomDocument();
$doc->loadHTML('<!doctype html>
<html><head>
<script>
$().ready(function() {});
</script>
</head>
<body>
</body>
</html>
', LIBXML_NOCDATA);
echo $doc->saveXML(null, LIBXML_NOCDATA);
?>
Output:
---------
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html>
<html><head>
<script><![CDATA[
$().ready(function() {});
]]></script>
</head>
<body>
</body>
</html>
---------
Changing
loadHTML to loadXML works as expected, no <![CDATA[ appears in
the output.
saveHTML also omits the CDATA tags but as I'm working with document fragments, this isn't
helpful as it wraps everything with html and body tags.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74241&edit=1