Skip to content

Commit 298f75b

Browse files
committed
bug #814 remove / character in the list of allowed character (matheo)
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
2 parents 0288ebd + cb79adf commit 298f75b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function preLexComponents(string $input): string
123123
private function consumeComponentName(string $customExceptionMessage = null): string
124124
{
125125
$start = $this->position;
126-
while ($this->position < $this->length && preg_match('/[A-Za-z0-9_:@\-\/.]/', $this->input[$this->position])) {
126+
while ($this->position < $this->length && preg_match('/[A-Za-z0-9_:@\-.]/', $this->input[$this->position])) {
127127
++$this->position;
128128
}
129129

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function getLexTests(): iterable
6262
'{{ component(\'foo\', { bar: true }) }}',
6363
];
6464

65+
yield 'attribute_with_no_value_and_no_attributes' => [
66+
'<twig:foo/>',
67+
'{{ component(\'foo\') }}',
68+
];
69+
6570
yield 'component_with_default_block_content' => [
6671
'<twig:foo>Foo</twig:foo>',
6772
'{% component \'foo\' %}{% block content %}Foo{% endblock %}{% endcomponent %}',
@@ -83,10 +88,6 @@ public function getLexTests(): iterable
8388
'<twig:foo-bar></twig:foo-bar>',
8489
'{% component \'foo-bar\' %}{% endcomponent %}',
8590
];
86-
yield 'component_with_character_/_on_his_name' => [
87-
'<twig:foo/bar></twig:foo/bar>',
88-
'{% component \'foo/bar\' %}{% endcomponent %}',
89-
];
9091
yield 'component_with_character_._on_his_name' => [
9192
'<twig:foo.bar></twig:foo.bar>',
9293
'{% component \'foo.bar\' %}{% endcomponent %}',

0 commit comments

Comments
 (0)