Skip to content

Commit 0f8072a

Browse files
matheoweaverryan
authored andcommitted
[TwigComponent] fixing issue with files finishing with comments
1 parent 846b671 commit 0f8072a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
4646
$output .= $this->consumeUntil('#}');
4747
$this->consume('#}');
4848
$output .= '#}';
49+
50+
if ($this->position === $this->length) {
51+
break;
52+
}
4953
}
5054

5155
if ($this->consume('<twig:')) {

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,15 @@ public function getLexTests(): iterable
171171
'{# <twig:Alert/> #} <twig:Alert/>',
172172
'{# <twig:Alert/> #} {{ component(\'Alert\') }}',
173173
];
174+
175+
yield 'file_ended_with_comments' => [
176+
'{# <twig:Alert/> #}',
177+
'{# <twig:Alert/> #}',
178+
];
179+
180+
yield 'mixing_component_and_file_ended_with_comments' => [
181+
'<twig:Alert/> {# <twig:Alert/> #}',
182+
'{{ component(\'Alert\') }} {# <twig:Alert/> #}',
183+
];
174184
}
175185
}

0 commit comments

Comments
 (0)