diff --git a/src/TwigComponent/src/Twig/TwigPreLexer.php b/src/TwigComponent/src/Twig/TwigPreLexer.php index 5fb5f231b73..1aee69ac8d1 100644 --- a/src/TwigComponent/src/Twig/TwigPreLexer.php +++ b/src/TwigComponent/src/Twig/TwigPreLexer.php @@ -193,7 +193,7 @@ private function consumeAttributes(string $componentName): string throw new SyntaxError(sprintf('Expected "=" after ":%s" when parsing the "line); } - $attributes[] = sprintf('%s: true', $key); + $attributes[] = sprintf('%s: true', preg_match('/[-:]/', $key) ? "'$key'" : $key); $this->consumeWhitespace(); continue; } diff --git a/src/TwigComponent/tests/Unit/TwigPreLexerTest.php b/src/TwigComponent/tests/Unit/TwigPreLexerTest.php index cbdb86c3b3d..605c0b2dcdc 100644 --- a/src/TwigComponent/tests/Unit/TwigPreLexerTest.php +++ b/src/TwigComponent/tests/Unit/TwigPreLexerTest.php @@ -167,6 +167,11 @@ public function getLexTests(): iterable '{% component \'foobar\' with { \'my:attribute\': \'yo\' } %}{% endcomponent %}', ]; + yield 'component_with_truthy_attribute' => [ + '', + '{% component \'foobar\' with { \'data-turbo-stream\': true } %}{% endcomponent %}', + ]; + yield 'ignore_twig_comment' => [ '{# #} ', '{# #} {{ component(\'Alert\') }}',