Req #73175 [Opn->Csd]: DOMDocument::saveHTML's void elements list is not updated
| From: | cmb@php.net | Date: | Fri, 12 Mar 2021 12:59:06 +0000 |
| Subject: | Req #73175 [Opn->Csd]: DOMDocument::saveHTML's void elements list is not updated | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232675@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73175&edit=1
ID: 73175
Updated by: cmb@php.net
Reported by: duhamelantoine1995 at gmail dot com
Summary: DOMDocument::saveHTML's void elements list is not
updated
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: DOM XML related
Operating System: Debian 8
PHP Version: 7.0.11
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This is a known limitation of libxml2, and apparently there are no
plans to ever fix this. There is not much we can do about it.
Previous Comments:
------------------------------------------------------------------------
[2016-09-26 09:42:40] duhamelantoine1995 at gmail dot com
Description:
------------
The DOMDocument::saveHTML and DOMDocument::saveHTMLFile methods does not product valid HTML when
using void elements introduced in HTML5.
The official HTML definition give a complete list of the void elements in HTML: https://www.w3.org/TR/html-markup/syntax.html#syntax-elements
> The following is a complete list of the void elements in HTML:
>
> area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track,
> wbr
In my tests (PHP 5&7, Debian 8 and Windows 10), PHP DOM render the following tags as non-void
elements:
- command
- embed
- keygen
- source
- track
- wbr
Test script:
---------------
$implementation = new DOMImplementation;
$dom = $implementation->createDocument(
null,
'html',
$implementation->createDocumentType('html', null, null)
);
$dom->formatOutput = true;
$body = $dom->createElement('body');
$div = $dom->createElement('div');
$dom->documentElement->appendChild($body);
$body->appendChild($div);
$voidElem = ['area', 'base', 'br', 'col',
'command', 'embed', 'hr', 'img', 'input',
'keygen', 'link', 'meta', 'param', 'source',
'track', 'wbr',];
foreach ($voidElem as $tagName) {
$div->appendChild($dom->createElement($tagName));
}
echo $dom->saveHTML();
Expected result:
----------------
<!DOCTYPE html>
<html><body><div>
<area>
<base>
<br><col>
<command><embed><hr>
<img><input><keygen><link>
<meta>
<param>
<source><track><wbr>
</div></body></html>
Actual result:
--------------
<!DOCTYPE html>
<html><body><div>
<area>
<base>
<br><col>
<command></command><embed></embed><hr>
<img><input><keygen></keygen><link>
<meta>
<param>
<source></source><track></track><wbr></wbr>
</div></body></html>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73175&edit=1