File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed
Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ final class TempestViewLexer
1010
1111 private ?string $ current ;
1212
13+ private bool $ eof = false ;
14+
1315 public function __construct (
1416 private readonly string $ html ,
1517 ) {
@@ -155,7 +157,7 @@ private function lexPhp(): Token
155157 {
156158 $ buffer = '' ;
157159
158- while ($ this ->seek (2 ) !== '?> ' ) {
160+ while ($ this ->seek (2 ) !== '?> ' && $ this -> current ) {
159161 $ buffer .= $ this ->consume ();
160162 }
161163
@@ -175,7 +177,7 @@ private function lexComment(): Token
175177 {
176178 $ buffer = '' ;
177179
178- while ($ this ->seek (3 ) !== '--> ' ) {
180+ while ($ this ->seek (3 ) !== '--> ' && $ this -> current ) {
179181 $ buffer .= $ this ->consume ();
180182 }
181183
Original file line number Diff line number Diff line change @@ -220,6 +220,24 @@ public function test_attribute_with_new_line(): void
220220 ], $ tokens );
221221 }
222222
223+ public function test_unclosed_php_tag (): void
224+ {
225+ $ tokens = new TempestViewLexer ('<?php echo "hi"; ' )->lex ();
226+
227+ $ this ->assertTokens ([
228+ new Token ('<?php echo "hi"; ' , TokenType::PHP ),
229+ ], $ tokens );
230+ }
231+
232+ public function test_unclosed_comment_tag (): void
233+ {
234+ $ tokens = new TempestViewLexer ('<!-- comment ' )->lex ();
235+
236+ $ this ->assertTokens ([
237+ new Token ('<!-- comment ' , TokenType::COMMENT ),
238+ ], $ tokens );
239+ }
240+
223241 private function assertTokens (array $ expected , TokenCollection $ actual ): void
224242 {
225243 $ this ->assertCount (count ($ expected ), $ actual );
Original file line number Diff line number Diff line change @@ -709,4 +709,13 @@ public function test_escape_expression_attribute(): void
709709
710710 $ this ->assertSnippetsMatch ('<div :escaped="foo"></div> ' , $ html );
711711 }
712+
713+ public function test_unclosed_php_tag (): void
714+ {
715+ $ html = $ this ->render (<<<'HTML'
716+ <?php echo 'hi';
717+ HTML);
718+
719+ $ this ->assertSame ('hi ' , $ html );
720+ }
712721}
You can’t perform that action at this time.
0 commit comments