Skip to content

Commit 92dcfba

Browse files
author
matheo
committed
Ignore verbatim block during Prelexing
1 parent b1aba24 commit 92dcfba

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public function preLexComponents(string $input): string
3737
$output = '';
3838

3939
while ($this->position < $this->length) {
40+
// ignore content inside verbatim block #947
41+
if ($this->consume('{% verbatim %}')) {
42+
$output .= '{% verbatim %}';
43+
$output .= $this->consumeUntil('{% endverbatim %}');
44+
$this->consume('{% endverbatim %}');
45+
$output .= '{% endverbatim %}';
46+
47+
if ($this->position === $this->length) {
48+
break;
49+
}
50+
}
51+
4052
// ignore content inside twig comments, see #838
4153
if ($this->consume('{#')) {
4254
$output .= '{#';

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,10 @@ public function getLexTests(): iterable
206206
'<twig:Alert/> {# <twig:Alert/> #}',
207207
'{{ component(\'Alert\') }} {# <twig:Alert/> #}',
208208
];
209+
210+
yield 'ignore_content_of_verbatim_block' => [
211+
'{% verbatim %}<twig:Alert/>{% endverbatim %}',
212+
'{% verbatim %}<twig:Alert/>{% endverbatim %}',
213+
];
209214
}
210215
}

0 commit comments

Comments
 (0)