Skip to content

Commit 37c68fa

Browse files
committed
Only use self closing html tags for void elements
1 parent 89939d3 commit 37c68fa

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

lib/internal/Magento/Framework/View/Helper/SecureHtmlRender/HtmlRenderer.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@
1313
*/
1414
class HtmlRenderer
1515
{
16+
17+
/**
18+
* List of void elements which require a self-closing tag and don't allow content
19+
*
20+
* @var array
21+
*/
22+
private const VOID_ELEMENTS = [
23+
'area',
24+
'base',
25+
'br',
26+
'col',
27+
'command',
28+
'embed',
29+
'hr',
30+
'img',
31+
'input',
32+
'keygen',
33+
'link',
34+
'meta',
35+
'param',
36+
'source',
37+
'track',
38+
'wbr'
39+
];
40+
1641
/**
1742
* @var Escaper
1843
*/
@@ -49,10 +74,10 @@ public function renderTag(TagData $tagData): string
4974
}
5075

5176
$html = '<' .$tagData->getTag() .$attributesHtml;
52-
if ($content) {
53-
$html .= '>' .$content .'</' .$tagData->getTag() .'>';
54-
} else {
77+
if (in_array($tagData->getTag(), self::VOID_ELEMENTS)) {
5578
$html .= '/>';
79+
} else {
80+
$html .= '>' .$content .'</' .$tagData->getTag() .'>';
5681
}
5782

5883
return $html;

0 commit comments

Comments
 (0)