feulf / raintpl3

The easiest Template Engine for PHP
https://feulf.github.io/raintpl
258 stars 57 forks source link

Fix PHP Parse error: syntax error, unexpected '}', fix #153 #196

Closed Manawyrm closed 5 years ago

Manawyrm commented 5 years ago

Hi,

this fixes an issue in the ternary parser. This causes the template parsing to fail in a case where { ? : accidentally follow in a template, even when the { is followed by a } (and is thus a valid tag).

This fixes the issue by disallowing a } within the ternary expression and fixes the issue.

I believe this is also the same issue reported by @st2cs in https://github.com/feulf/raintpl3/issues/153 .

Thanks, Tobias

feulf commented 5 years ago

Looks good, could you please post an example?

Manawyrm commented 5 years ago

Sure.

Rain\Tpl::configure( array(
        "base_url"              => null,
        "tpl_dir"               => "tmp/tpl",
        "cache_dir"             => "tmp/tpl",
        "path_replace"  => false,
) );

$template = '
Demo: {HI12345}
yada yada demo question? Look here: https://myurl.de/{$somevariable}/
';

$tpl = new Rain\Tpl();

$response =  $tpl->drawString( $template, true );

This causes a crash when evaluating the template.

PHP Parse error:  syntax error, unexpected '}' in 
/var/www/tmp/tpl/238ab0eeb8453154befb4aa481560096.s.rtpl.php on line 3
feulf commented 5 years ago

@Manawyrm just tested your code change. It does fix that issue. Thanks so much for working on it!