Skip to content

Commit 72529e0

Browse files
committed
[TwigComponent] Fix lexer to escape truthy attribute names
1 parent 846b671 commit 72529e0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private function consumeAttributes(string $componentName): string
193193
throw new SyntaxError(sprintf('Expected "=" after ":%s" when parsing the "<twig:%s" syntax.', $key, $componentName), $this->line);
194194
}
195195

196-
$attributes[] = sprintf('%s: true', $key);
196+
$attributes[] = sprintf('%s: true', preg_match('/[-:]/', $key) ? "'$key'" : $key);
197197
$this->consumeWhitespace();
198198
continue;
199199
}

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ public function getLexTests(): iterable
167167
'{% component \'foobar\' with { \'my:attribute\': \'yo\' } %}{% endcomponent %}',
168168
];
169169

170+
yield 'component_with_truthy_attribute' => [
171+
'<twig:foobar data-turbo-stream></twig:foobar>',
172+
'{% component \'foobar\' with { \'data-turbo-stream\': true } %}{% endcomponent %}',
173+
];
174+
170175
yield 'ignore_twig_comment' => [
171176
'{# <twig:Alert/> #} <twig:Alert/>',
172177
'{# <twig:Alert/> #} {{ component(\'Alert\') }}',

0 commit comments

Comments
 (0)