Project

General

Profile

Actions

Feature #89389

closed

xmlRecompileFromStructValArray creates invalid HTML code

Added by Jo Hasenau over 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Miscellaneous
Target version:
Start date:
2019-10-10
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
easy
Sprint Focus:

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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #40503: XHTML 5Closed2012-09-01

Actions
Actions #1

Updated by Jo Hasenau over 4 years ago

  • Description updated (diff)
Actions #2

Updated by Jo Hasenau over 4 years ago

Just for clarification here is a good explanation of the problems caused by falsely self closing tags: https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5

Actions #3

Updated by Jo Hasenau over 4 years ago

Here is a list of tags that are officially considered to be void: https://riptutorial.com/html/example/4736/void-elements

Actions #4

Updated by Georg Ringer over 4 years ago

so I guess it would be enough to just add a check for the mentioned tag names?

Actions #5

Updated by Jo Hasenau over 4 years ago

Yep - I did some quick fixes for the L10nmgr so people don't have to wait for a new core release.
But basically that's it:
https://gitlab.com/coderscare/l10nmgr/blob/7-0/Classes/Model/Tools/XmlTools.php#L237

Actions #6

Updated by Jo Hasenau over 4 years ago

  • Status changed from New to In Progress
  • Assignee set to Jo Hasenau
Actions #7

Updated by Gerrit Code Review over 4 years ago

  • Status changed from In Progress to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61946

Actions #8

Updated by Gerrit Code Review over 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61946

Actions #9

Updated by Gerrit Code Review over 4 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61946

Actions #10

Updated by Susanne Moog about 4 years ago

Actions #11

Updated by Susanne Moog about 4 years ago

  • Tracker changed from Bug to Feature
  • Status changed from Under Review to Closed

This is a duplicate of #40503

Actions

Also available in: Atom PDF