Important: #111440 - HTML transformation uses native HTML5 parser
See forge#111440
Description
The internal class
\TYPO3\, which backs the
Fluid ViewHelper
<f:, no longer parses markup with the
third-party library masterminds/. It now uses the native, spec-compliant
HTML5 parser of PHP,
\Dom\, available since PHP 8.4.
Along with this, the internal class
\TYPO3\ and the public
service
\Masterminds\ have been removed from the dependency
injection container, and masterminds/ is no longer a direct requirement
of typo3/. The library is still installed as a dependency of
typo3/, so HTML sanitizing,
parse and RTE
processing are not affected. Extensions that injected or fetched the service
\Masterminds\ must either require masterminds/ themselves
and instantiate the parser, or switch to
\Dom\.
The native parser is implemented in C. In a local measurement on PHP 8.5 with
an HTML document of about 510 KB, parsing and serializing took about 8 ms
instead of about 130 ms with masterminds/. The actual gain depends on
the markup, but is in the order of magnitude of 12 to 16 times faster.
The native parser follows the WHATWG HTML parsing and serialization
algorithms, the markup is parsed as a fragment in the context of a
<div>
element. This results in the following differences:
| Input | Output (before) | Output (now) |
|---|---|---|
<a href>visit</ |
<a href>visit</ |
<a href="">visit</ |
<custom- |
<custom- |
<custom- |
<td>cell</ |
<td>cell</ |
cell
|
<table>text<tr><td>cell</ | unchanged |
text<table><tbody><tr><td>cell</ |
<svg><path d="M0 0"/></ |
<svg><path d="M0 0" /></ |
<svg><path d="M0 0"></ |
- Empty attributes are serialized with an empty value, for example
<img alt>becomes<img alt="">anddisabledbecomesdisabled="". - The self-closing syntax is not honoured for non-void HTML elements.
- Table cells and rows outside of a table lose their tag, an implied
<tbody>is added, and misplaced content is moved in front of the table. - Node and attribute names of the ViewHelper argument
selectorare matched case-insensitively,A.now matchesHREF <a href="...">.
Entities, void elements such as
<br>
, the raw content of
<script>
and
<style>
, comments and the on behaviours
are unchanged.
The changes only apply where
<f: is used. In TYPO3 Core,
these are the labels and texts of EXT:form rendered in the frontend (checkbox
labels, static text elements, the summary page, the confirmation finisher and
the default email finisher template), as well as the news on the backend login
screen and the module descriptions of the backend submodule overview. Custom
templates and extensions using the ViewHelper are affected as well and should
check their rendered output if they pass unusual or invalid markup.