Skip to content

Fix error for component name with : #806

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
Apr 19, 2023
Merged

Conversation

WebMamba
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
Tickets Fix #803
License MIT

@WebMamba
Copy link
Contributor Author

This is a fix on the HTML twig component syntax but do you think we should extend the fix to allow this
{% component foo:bar for the moment only {% component 'foo:bar' %} is allow?

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

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

Thanks for getting this rolling ❤️

];

yield 'component_with_default_block_that_holds_a_component_and_multi_blocks' => [
'<twig:foo>Foo <twig:bar /><twig:block name="other_block">Other block</twig:block></twig:foo>',
'{% component foo %}{% block content %}Foo {% component bar %}{% endcomponent %}{% endblock %}{% block other_block %}Other block{% endblock %}{% endcomponent %}',
'{% component \'foo\' %}{% block content %}Foo {% component \'bar\' %}{% endcomponent %}{% endblock %}{% block other_block %}Other block{% endblock %}{% endcomponent %}',
];
Copy link
Member

Choose a reason for hiding this comment

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

Let's add tests specifically for any of the new character we allow - e.g. <twig:foo:bar or <twig:foo-bar, etc

@@ -58,7 +58,7 @@ public function preLexComponents(string $input): string
$this->currentComponents[] = ['name' => $componentName, 'hasDefaultBlock' => false];
}

$output .= "{% component {$componentName}".($attributes ? " with { {$attributes} }" : '').' %}';
$output .= "{% component '{$componentName}'".($attributes ? " with { {$attributes} }" : '').' %}';
Copy link
Member

Choose a reason for hiding this comment

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

Does {% component @foo/bar-baz.html.twig %} (no ') not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes It works with both

@weaverryan
Copy link
Member

Thanks Matheo!

@weaverryan weaverryan merged commit 4453798 into symfony:2.x Apr 19, 2023
@Jupi007
Copy link

Jupi007 commented Apr 19, 2023

Thanks a lot for the fix @WebMamba !

weaverryan added a commit that referenced this pull request Apr 24, 2023
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

remove / character in the list of allowed character

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       |
| License       | MIT

By allowing the / character in #806, we introduce a bug. You can't now use the self-closing syntax because it enters in conflict with the component name.
```php
<twig:foo/>
```
The Lexer thinks now that the name is `foo/`
I just remove the / from the allowing list, tell me if you think we should go a bit further.

Commits
-------

cb79adf remove / character in the list of allowed character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TwigComponent] namespace double dot isn't parsed correctly
5 participants