File tree Expand file tree Collapse file tree 5 files changed +31
-2
lines changed
Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tempest \View \Exceptions ;
4+
5+ use Exception ;
6+
7+ final class InvalidClosingTag extends Exception
8+ {
9+ public function __construct (string $ openTag , string $ closingTag )
10+ {
11+ parent ::__construct ("Invalid closing tag ` {$ closingTag }` for opening tag ` {$ openTag }` " );
12+ }
13+ }
Original file line number Diff line number Diff line change 22
33namespace Tempest \View \Parser ;
44
5+ use Tempest \View \Exceptions \InvalidClosingTag ;
6+
57use function Tempest \Support \str ;
68
79final class Token
@@ -79,6 +81,10 @@ public function setEndingToken(Token $endingToken): void
7981
8082 public function setClosingToken (Token $ closingToken ): void
8183 {
84+ if ($ closingToken ->tag && $ this ->tag !== $ closingToken ->tag ) {
85+ throw new InvalidClosingTag ($ this ->tag , $ closingToken ->tag );
86+ }
87+
8288 $ this ->closingToken = $ closingToken ;
8389 }
8490
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ <h1 id="top" class="mt-2 font-bold text-4xl text-(--ui-text-highlighted) lg:scro
108108 </ li >
109109 < li :foreach ="$chapter['children'] as $url => $title ">
110110 < a :href ="$url " :data-on-this-page ="$title " class ="pl-4 group relative text-sm flex items-center focus-visible:outline-(--ui-primary) py-1 text-(--ui-text-dimmed) hover:text-(--ui-text) data-[active]:text-(--ui-primary) transition-colors ">
111- {{ \Tempest\Support\Str\strip_tags($title) }}</ span >
111+ < span > {{ \Tempest\Support\Str\strip_tags($title) }}</ span >
112112 </ a >
113113 </ li >
114114 </ x-template >
Original file line number Diff line number Diff line change 55use Generator ;
66use PHPUnit \Framework \Attributes \DataProvider ;
77use PHPUnit \Framework \TestCase ;
8+ use Tempest \View \Exceptions \InvalidClosingTag ;
89use Tempest \View \Parser \TempestViewLexer ;
910use Tempest \View \Parser \TempestViewParser ;
1011use Tempest \View \Parser \Token ;
@@ -66,6 +67,15 @@ public function test_self_closing_tags_with_attributes(): void
6667 HTML, $ ast ->compile ());
6768 }
6869
70+ public function test_invalid_closing_tag (): void
71+ {
72+ $ tokens = new TempestViewLexer ('<a></span></a> ' )->lex ();
73+
74+ $ this ->expectException (InvalidClosingTag::class);
75+
76+ new TempestViewParser ($ tokens )->parse ();
77+ }
78+
6979 public function test_doctype (): void
7080 {
7181 $ tokens = new TokenCollection ([
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ public function test_auto_registration_with_x_component(): void
5353 $ discovery ->apply ();
5454
5555 $ html = $ this ->render (<<<'HTML'
56- <x-auto-registered-with-declaration></x-auto-registered-with-x-component >
56+ <x-auto-registered-with-declaration></x-auto-registered-with-declaration >
5757 HTML);
5858
5959 $ this ->assertSame ('<span>Hello World</span> ' , $ html );
You can’t perform that action at this time.
0 commit comments