[php-src] Issue #9450: DOMDocument transforms content inside script
| From: | ncreea | Date: | Tue, 30 Aug 2022 14:59:55 +0000 |
| Subject: | [php-src] Issue #9450: DOMDocument transforms content inside script | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242340@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9450
Author: ncreea
### Description
The following code:
```php
header('Content-type: text/plain');
$content = "
<html lang=\"en-US\">
<head></head>
<body>
<script>alert('<div>something</div>');</script>
</body>
</html>";
echo "This:\n$content\n\n";
$doc = new \DOMDocument();
$doc->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$con = $doc->saveHtml();
echo "Transformed to:\n$con\n\n";
```
Resulted in this output:
```
This:
<html lang="en-US">
<head></head>
<body>
<script>alert('<div>something</div>');</script>
</body>
</html>
Transformed to:
<html lang="en-US">
<head></head>
<body>
<script>alert('<div>something');</script>
</body>
</html>
```
But I expected this output instead:
```
This:
<html lang="en-US">
<head></head>
<body>
<script>alert('<div>something</div>');</script>
</body>
</html>
Transformed to:
<html lang="en-US">
<head></head>
<body>
<script>alert('<div>something</div>');</script>
</body>
</html>
```
### PHP Version
PHP 7.3.33 and 8.0.22
### Operating System
FreeBSD 12.3 and Rocky Linux 9