Skip to content

Commit 9e2b177

Browse files
committed
bug #847 [TwigComponent] fixing issue with files finishing with comments (matheo)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [TwigComponent] fixing issue with files finishing with comments | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | Fix #846 | License | MIT Commits ------- 0f8072a [TwigComponent] fixing issue with files finishing with comments
2 parents 846b671 + 0f8072a commit 9e2b177

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)