php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74628 DOM auto remove HTML closing tag in <script> tag when save
Submitted: 2017-05-22 04:27 UTC Modified: 2017-05-22 16:37 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:0 (0.0%)
From: tidus2102 at gmail dot com Assigned:
Status: Suspended Package: DOM XML related
PHP Version: 7.1.5 OS: OSX El Capitan
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-05-22 04:27 UTC] 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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-22 16:37 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2017-05-22 16:37 UTC] 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>.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 14 03:01:30 2019 UTC