8000 [TwigComponent] Fix lexer to escape attribute name when it contains dashes by norkunas · Pull Request #837 · symfony/ux · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[TwigComponent] Fix lexer to escape attribute name when it contains dashes #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2023

Conversation

norkunas
Copy link
Contributor
@norkunas norkunas commented May 3, 2023
Q A
Bug fix? yes
New feature? no
Tickets Fix #...
License MIT

Hello :) back from holidays and now testing new features, so this is the second thing I've found.
Will open an issue about the first one.

@@ -200,7 +200,7 @@ private function consumeAttributes(string $componentName): string
$attributeValue = $this->consumeAttributeValue($quote);
}

$attributes[] = sprintf('%s: %s', $key, $attributeValue);
$attributes[] = sprintf('%s: %s', str_contains($key, '-') ? "'$key'" : $key, $attributeValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should escape all the attributes. We can have the same issue with names containing : for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i forgot about colons. Tried to escape always but then some of tests throws:

2) Symfony\UX\TwigComponent\Tests\Unit\TwigPreLexerTest::testPreLex with data set "component_with_embedded_component_inside_block" ('<twig:foo><twig:block name="f...g:foo>', '{% component 'foo' %}{% block...ent %}')
Twig\Error\SyntaxError: Expected block name at line 1.

@weaverryan
Copy link
Member

Very nice - thank you @norkunas! We may hit other edge cases and need to escape more. I'm not too worried - that test suite is getting more and more cases all the time.

@weaverryan weaverryan merged commit 4b227b1 into symfony:2.x May 3, 2023
@norkunas norkunas deleted the fix-lexer branch May 4, 2023 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
48B0 Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0