[ticket/11833] Prevent Twig errors from invalid template loops using BEGINELSE

PHPBB3-11833
This commit is contained in:
Nathan Guse 2013-09-09 11:26:40 -05:00
parent 0cb4ceabf4
commit 5166240d62

View file

@ -161,6 +161,9 @@ class phpbb_template_twig_lexer extends Twig_Lexer
$subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis $subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis
$body = $matches[3]; $body = $matches[3];
// Replace <!-- BEGINELSE -->
$body = str_replace('<!-- BEGINELSE -->', '{% else %}', $body);
// Is the designer wanting to call another loop in a loop? // Is the designer wanting to call another loop in a loop?
// <!-- BEGIN loop --> // <!-- BEGIN loop -->
// <!-- BEGIN !loop2 --> // <!-- BEGIN !loop2 -->
@ -205,9 +208,6 @@ class phpbb_template_twig_lexer extends Twig_Lexer
return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}";
}; };
// Replace <!-- BEGINELSE --> correctly, only needs to be done once
$code = str_replace('<!-- BEGINELSE -->', '{% else %}', $code);
return preg_replace_callback('#<!-- BEGIN ([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1 -->#s', $callback, $code); return preg_replace_callback('#<!-- BEGIN ([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1 -->#s', $callback, $code);
} }