File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,7 @@ private function consumeBlock(string $componentName): string
314314 if (!$ this ->doesStringEventuallyExist ($ closingTag )) {
315315 throw new SyntaxError ("Expected closing tag ' {$ closingTag }' for block ' {$ blockName }'. " , $ this ->line );
316316 }
317- $ blockContents = $ this ->consumeUntil ( $ closingTag );
317+ $ blockContents = $ this ->consumeUntilEndBlock ( );
318318
319319 $ subLexer = new self ($ this ->line );
320320 $ output .= $ subLexer ->preLexComponents ($ blockContents );
@@ -325,6 +325,33 @@ private function consumeBlock(string $componentName): string
325325 return $ output ;
326326 }
327327
328+ private function consumeUntilEndBlock (): string
329+ {
330+ $ start = $ this ->position ;
331+
332+ $ depth = 1 ;
333+ while ($ this ->position < $ this ->length ) {
334+ if ('</twig:block ' === substr ($ this ->input , $ this ->position , 12 )) {
335+ if (1 === $ depth ) {
336+ break ;
337+ } else {
338+ --$ depth ;
339+ }
340+ }
341+
342+ if ('<twig:block ' === substr ($ this ->input , $ this ->position , 11 )) {
343+ ++$ depth ;
344+ }
345+
346+ if ("\n" === $ this ->input [$ this ->position ]) {
347+ ++$ this ->line ;
348+ }
349+ ++$ this ->position ;
350+ }
351+
352+ return substr ($ this ->input , $ start , $ this ->position - $ start );
353+ }
354+
328355 private function doesStringEventuallyExist (string $ needle ): bool
329356 {
330357 $ remainingString = substr ($ this ->input , $ this ->position );
Original file line number Diff line number Diff line change @@ -92,5 +92,9 @@ public function getLexTests(): iterable
9292 '<twig:foo.bar></twig:foo.bar> ' ,
9393 '{% component \'foo.bar \' %}{% endcomponent %} ' ,
9494 ];
95+ yield 'nested_component_2_levels ' => [
96+ '<twig:foo><twig:block name="child"><twig:bar><twig:block name="message">Hello World!</twig:block></twig:bar></twig:block></twig:foo> ' ,
97+ '{% component \'foo \' %}{% block child %}{% component \'bar \' %}{% block message %}Hello World!{% endblock %}{% endcomponent %}{% endblock %}{% endcomponent %} ' ,
98+ ];
9599 }
96100}
You can’t perform that action at this time.
0 commit comments