Skip to content

Commit b15dff5

Browse files
committed
bug #848 [TwigComponent] Fix lexer to escape truthy attribute names (norkunas)
This PR was merged into the 2.x branch. Discussion ---------- [TwigComponent] Fix lexer to escape truthy attribute names | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | Fix #... | License | MIT Missed this one 😞 Commits ------- 72529e0 [TwigComponent] Fix lexer to escape truthy attribute names
2 parents 9e2b177 + 72529e0 commit b15dff5

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
@@ -197,7 +197,7 @@ private function consumeAttributes(string $componentName): string
197197
throw new SyntaxError(sprintf('Expected "=" after ":%s" when parsing the "<twig:%s" syntax.', $key, $componentName), $this->line);
198198
}
199199

200-
$attributes[] = sprintf('%s: true', $key);
200+
$attributes[] = sprintf('%s: true', preg_match('/[-:]/', $key) ? "'$key'" : $key);
201201
$this->consumeWhitespace();
202202
continue;
203203
}

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)