Issue Feature Closed

#89389xmlRecompileFromStructValArray creates invalid HTML code

Jo Hasenau 10/10/19, 13:08 updated 03/27/20, 12:26

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>
<script type="text/javascript" src="https://some.tld/something.js"><br /></code></pre>which is valid XML but invalid HTML5 and will lead to a broken frontend output.<br />Same for other tags like <span> <p>We found out about this behaviour, because translated HTML content elements were broken after exporting and reimporting them with the L10nmgr.<br />Still this should be a problem for any other usage of xml2tree dealing with empty tags, that should not be self closing.</p> <p>This is broken in any supported version from CMS 6 up to CMS 10.</p></script>

Reviews 1