Feature #89389
closedxmlRecompileFromStructValArray creates invalid HTML code
0%
Description
While making use of xml2tree the function xmlRecompileFromStructValArray is involved to "implode an array of XML parts (made with xml_parse_into_struct()) into XML again."
If there are opening and closing tags in the same line, the type reported by xml_parse_into_struct is "complete".
In this case, there is a check for the content of the given tag and if that is empty, the tag will be made a self closing tag no matter what.
if ($type == 'complete') {
if (isset($val['value'])) {
$XMLcontent .= '>' . htmlspecialchars($val['value']) . '</' . $val['tag'] . '>';
} else {
$XMLcontent .= '/>';
}
}
This will convert code like
<script type="text/javascript" src="https://some.tld/something.js"></script>
to<script type="text/javascript" src="https://some.tld/something.js"/>
which is valid XML but invalid HTML5 and will lead to a broken frontend output.Same for other tags like <span>
We found out about this behaviour, because translated HTML content elements were broken after exporting and reimporting them with the L10nmgr.
Still this should be a problem for any other usage of xml2tree dealing with empty tags, that should not be self closing.
This is broken in any supported version from CMS 6 up to CMS 10.