php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73175 DOMDocument::saveHTML's void elements list is not updated
Submitted: 2016-09-26 09:42 UTC Modified: -
Votes:5
Avg. Score:4.2 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:0 (0.0%)
From: duhamelantoine1995 at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.0.11 OS: Debian 8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: duhamelantoine1995 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-09-26 09:42 UTC] 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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Nov 18 23:01:35 2019 UTC