@@ -263,10 +263,6 @@ private function consumeAttributes(string $componentName): string
263263 */
264264 private function consume (string $ string ): bool
265265 {
266- if ($ string [0 ] !== $ this ->input [$ this ->position ]) {
267- return false ;
268- }
269-
270266 $ stringLength = \strlen ($ string );
271267 if (substr ($ this ->input , $ this ->position , $ stringLength ) === $ string ) {
272268 $ this ->position += $ stringLength ;
@@ -405,16 +401,24 @@ private function consumeUntilEndBlock(): string
405401 $ start = $ this ->position ;
406402
407403 $ depth = 1 ;
404+ $ inComment = false ;
408405 while ($ this ->position < $ this ->length ) {
409- if ('</twig:block ' === substr ($ this ->input , $ this ->position , 12 )) {
406+ if ($ inComment && '#} ' === substr ($ this ->input , $ this ->position , 2 )) {
407+ $ inComment = false ;
408+ }
409+ if (!$ inComment && '{# ' === substr ($ this ->input , $ this ->position , 2 )) {
410+ $ inComment = true ;
411+ }
412+
413+ if (!$ inComment && '</twig:block> ' === substr ($ this ->input , $ this ->position , 13 )) {
410414 if (1 === $ depth ) {
411415 break ;
412416 } else {
413417 --$ depth ;
414418 }
415419 }
416420
417- if ('{% endblock %} ' === substr ($ this ->input , $ this ->position , 14 )) {
421+ if (! $ inComment && '{% endblock %} ' === substr ($ this ->input , $ this ->position , 14 )) {
418422 if (1 === $ depth ) {
419423 // in this case, we want to advanced ALL the way beyond the endblock
420424 $ this ->position += 14 ;
@@ -424,11 +428,11 @@ private function consumeUntilEndBlock(): string
424428 }
425429 }
426430
427- if ('<twig:block ' === substr ($ this ->input , $ this ->position , 11 )) {
431+ if (! $ inComment && '<twig:block ' === substr ($ this ->input , $ this ->position , 11 )) {
428432 ++$ depth ;
429433 }
430434
431- if ('{% block ' === substr ($ this ->input , $ this ->position , 8 )) {
435+ if (! $ inComment && '{% block ' === substr ($ this ->input , $ this ->position , 8 )) {
432436 ++$ depth ;
433437 }
434438
0 commit comments