Skip to content

Commit 20a2ee0

Browse files
author
matheo
committed
Ignore twig comments when prelexing
1 parent 8e214d4 commit 20a2ee0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
4040
$output = '';
4141

4242
while ($this->position < $this->length) {
43+
// ignore content inside twig comments, see #838
44+
if ($this->consume('{#')) {
45+
$output .= '{#';
46+
$output .= $this->consumeUntil('#}');
47+
$this->consume('#}');
48+
$output .= '#}';
49+
}
50+
4351
if ($this->consume('<twig:')) {
4452
$componentName = $this->consumeComponentName();
4553

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,10 @@ public function getLexTests(): iterable
151151
] }) }}
152152
EOF
153153
];
154+
155+
yield 'ignore_twig_comment' => [
156+
'{# <twig:Alert/> #} <twig:Alert/>',
157+
'{# <twig:Alert/> #} {{ component(\'Alert\') }}',
158+
];
154159
}
155160
}

0 commit comments

Comments
 (0)