Skip to content

Commit 0b25975

Browse files
authored
fix(view): prevent compiling parent elements of minified void tags (#1055)
1 parent 3d7cbbd commit 0b25975

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Tempest/View/src/Renderers/TempestViewCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function parseDom(string $template): NodeList
109109
$template = str($template)
110110
// Convert self-closing and void tags
111111
->replaceRegex(
112-
regex: '/<(?<element>\w.*?)\/>/',
112+
regex: '/<(?<element>\w[^<]*?)\/>/',
113113
replace: function (array $match) {
114114
$element = str($match['element'])->trim();
115115

tests/Integration/View/ViewComponentTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,15 @@ public function test_does_not_duplicate_br(): void
695695
<html lang="en"><head></head><body><br><hr></body></html>
696696
HTML, $html);
697697
}
698+
699+
public function test_renders_minified_html_with_void_elements(): void
700+
{
701+
$html = $this->render(<<<'HTML'
702+
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M7 9.667A2.667 2.667 0 0 1 9.667 7h8.666A2.667 2.667 0 0 1 21 9.667v8.666A2.667 2.667 0 0 1 18.333 21H9.667A2.667 2.667 0 0 1 7 18.333z"/><path d="M4.012 16.737A2 2 0 0 1 3 15V5c0-1.1.9-2 2-2h10c.75 0 1.158.385 1.5 1"/></g></svg>
703+
HTML);
704+
705+
$this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML'
706+
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewbox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M7 9.667A2.667 2.667 0 0 1 9.667 7h8.666A2.667 2.667 0 0 1 21 9.667v8.666A2.667 2.667 0 0 1 18.333 21H9.667A2.667 2.667 0 0 1 7 18.333z"></path><path d="M4.012 16.737A2 2 0 0 1 3 15V5c0-1.1.9-2 2-2h10c.75 0 1.158.385 1.5 1"></path></g></svg>
707+
HTML, $html);
708+
}
698709
}

0 commit comments

Comments
 (0)