Bug #74628 [Com]: DOM auto remove HTML closing tag in <script> tag when save
| From: | gijovarghese141 at gmail dot com | Date: | Thu, 04 Mar 2021 11:34:30 +0000 |
| Subject: | Bug #74628 [Com]: DOM auto remove HTML closing tag in <script> tag when save | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232537@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74628&edit=1
ID: 74628
Comment by: gijovarghese141 at gmail dot com
Reported by: tidus2102 at gmail dot com
Summary: DOM auto remove HTML closing tag in <script> tag
when save
Status: Suspended
Type: Bug
Package: DOM XML related
Operating System: OSX El Capitan
PHP Version: 7.1.5
Block user comment: N
Private report: N
New Comment:
Adding LIBXML_SCHEMA_CREATE to loadHTML() as an option will fix the issue
$dom->loadHTML($html, LIBXML_SCHEMA_CREATE);
Previous Comments:
------------------------------------------------------------------------
[2017-05-22 16:37:32] cmb@php.net
Unfortunately, libxml isn't really HTML5 compatible yet, and there
isn't much we can do about that. You have to stick to conforming
HTML 4.01, and write <\/h1>, see <https://3v4l.org/ldGmr>.
------------------------------------------------------------------------
[2017-05-22 04:27:10] tidus2102 at gmail dot com
Description:
------------
http://stackoverflow.com/questions/4029341/dom-parser-that-allows-html5-style-in-script-tag
DOM auto remove HTML closing tag in <script> tag when save. Please check test script below.
Test script:
---------------
$html = <<<HTML
<script>
console.log('<h1>aaa</h1>');
</script>
HTML;
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"),
LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
echo $dom->saveHTML();
die;
Expected result:
----------------
All content in <script> tag need to be exactly the same as original HTML code.
<script>
console.log('<h1>aaa</h1>');
</script>
Actual result:
--------------
<script>
console.log('<h1>aaa');
</script>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74628&edit=1