raintpl3
raintpl3 copied to clipboard
'Ternary' regex in parser.php wrong
Hi, the second ternary operator parser regex : {(.[^{?]?)?(.?):(.*?)} is wrong (parser.php, line 59). The problem is, that is also matches PHP code inserted by plugins that parsed the template with beforeParse. Example :
{$data.User.something}<a href="<?php echo static::$conf['base_url']; ?>users/{$data.User.otherthing}
The code above gets matched in total although it is not a ternary operator, because it has a '{' for a start a '}' for end and it has a '?' and ':' in it.
I believe this is a fundamental problem that need fixing, since a simple string like this :
{$startmeup} How are you ? Please, choose : one or two. {$endmenow}
will also get matched.
Maybe this : {(.[^{}?]?)?(.[^}?]?):(.*?)} would work better ... not 100% sure though.
Mhm, you can try it yourself and make a pull request if it would work :smile:
I already tried it and it looks like working. I'll be using it in that form at least ... but I'm not sure it covers all the cases properly. Don't know Rain.tpl in details, don't have the time to test deeply either.
Okey, so, you can also paste here some lines of changed code that we will be able to merge.
Parser.php, line 59 should be :
'ternary' => array('({.[^{?]??.?:.?})', '/{(.[^{}?]?)?(.[^}?]?):(.?)}/'),
I think.
Thank you.
That regexp will not parse: {($var>1)?"{$var}s":""}
But, {$data.User.something}
is not matched with {(.[^{?]*?)\?(.*?):(.*?)}
. What is full source?
@kargnas Updated the original issue post. Some markup was breaking it. Now full thing should be visible.
Update : Parser.php, line 59 should probably be :
'ternary' => array('({.[^{}?]??.[^}?]?:.?})', '/{(.[^{}?]?)?(.[^}?]?):(.?)}/'),
Forgot to fix the other regex.