I discovered this issue on our own sites, too. I shared a bit of this on Slack, it seems to be caused in the core/modules/filter/src/Plugin/Filter/FilterHtml.php
file's getHTMLRestrictions
implementation. The $dom = Html::load($html);
line uses the new HTML5 parser to convert the "allowed HTML tags" list into a deeply nested DOM data structure since the list has no closing tags. It then walks over the data structure and extracts tags and attribute names. Since iframes are not permitted to have any child content, the new parser drops any elements that would have been inside the iframe.
I found a couple short-term workarounds that worked:
- Move the
<iframe>
tag to the end of the list, so it doesn't have any child content when it gets parsed byHtml::load
and avoid adding new tags that come after the iframe until the issue is fixed. - Close the
<iframe>
tag in the list so it becomes something like<iframe></iframe>
. Drupal doesn't seem to encourage closing tags here, so using this workaround might cause a future issue.
Also, I'm not entirely sure, but I could imagine there being more elements than just the iframe that drop the child content. It's just that the iframe is one of the most common use cases with the HTML filter.
I discovered this issue on our own sites, too. I shared a bit of this on Slack, it seems to be caused in the core/modules/filter/src/Plugin/Filter/FilterHtml.php
file's getHTMLRestrictions
implementation. The $dom = Html::load($html);
line uses the new HTML5 parser to convert the "allowed HTML tags" list into a deeply nested DOM data structure since the list has no closing tags. It then walks over the data structure and extracts tags and attribute names. Since iframes are not permitted to have any child content, the new parser drops any elements that would have been inside the iframe.
I found a couple short-term workarounds that worked:
- Move the
<iframe>
tag to the end of the list, so it doesn't have any child content when it gets parsed byHtml::load
and avoid adding new tags that come after the iframe until the issue is fixed. - Close the
<iframe>
tag in the list so it becomes something like<iframe></iframe>
. Drupal doesn't seem to encourage closing tags here, so using this workaround might cause a future issue.
Also, I'm not entirely sure, but I could imagine there being more elements than just the iframe that drop the child content. It's just that the iframe is one of the most common use cases with the HTML filter.