Bug #70817 [Com]: DOMDocument save removes html within a string
| From: | alexeyseliverstov dot dev at gmail dot com | Date: | Wed, 27 Jun 2018 10:16:24 +0000 |
| Subject: | Bug #70817 [Com]: DOMDocument save removes html within a string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215988@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70817&edit=1
ID: 70817
Comment by: alexeyseliverstov dot dev at gmail dot com
Reported by: untuned20 at gmail dot com
Summary: DOMDocument save removes html within a string
Status: Open
Type: Bug
Package: DOM XML related
Operating System: Linux
PHP Version: 5.6.14
Block user comment: N
Private report: N
New Comment:
Just tried using this with PHP 7.1 on Ubuntu 16.04. For some reason, closing html tags inside the
script tag are deleted.
This is the warning that appears when I try to execute the code example: "Warning:
DOMDocument::loadHTML(): Unexpected end tag : h1 in Entity, line: 6 in Standard input code on line
5"
Previous Comments:
------------------------------------------------------------------------
[2015-10-30 00:49:11] untuned20 at gmail dot com
The above test script is wrong, it should be loadHTML() instead.
Test script:
---------------
<?php
$doc = new DOMDocument();
$doc->loadHTML('<html>
<head>
</head>
<body>
<script>
console.log("<h1>hello</h1>");
</script>
</body>
</html>');
echo $doc->saveHTML();
------------------------------------------------------------------------
[2015-10-30 00:44:37] untuned20 at gmail dot com
Description:
------------
When parsing a DOMDocument(), strings containing html are validated and probably shouldn't be.
For example when parsing a
<script> tag containing html to be executed, the
parser will validate that html. In the example script, The parser removes the
</h1> leaving an invalid string of "<h1>hello".
Test script:
---------------
<?php
$doc = new DOMDocument();
$doc->loadXML('<html>
<head>
</head>
<body>
<script>
console.log("<h1>hello</h1>");
</script>
</body>
</html>');
echo $doc->saveHTML();
Expected result:
----------------
<html>
<head>
</head>
<body>
<script>
console.log("<h1>hello</h1>");
</script>
</body>
</html>
Actual result:
--------------
<html>
<head>
</head>r
<body>
<script>
console.log("<h1>hello");
</script>
</body>
</html>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70817&edit=1