Fixed Templates: "if" conditions in some cases not translated correctly into PHP

nocte

Well-known member
Affected version
XF 2.2.10 Patch 1
Alternatively, this might be better:
Code:
diff --git a/xenforo/src/XF/Template/Compiler/Parser.y b/xenforo/src/XF/Template/Compiler/Parser.y
index 0a0784c..0e25bf3 100644
--- a/xenforo/src/XF/Template/Compiler/Parser.y
+++ b/xenforo/src/XF/Template/Compiler/Parser.y
@@ -156,7 +156,7 @@ expression_part(RES) ::= double_quoted(A). {
        }
 }
 expression_part(RES) ::= PAREN_START expression(A) PAREN_END. {
-       RES = A;
+       RES = new Syntax\Expression(A, $this->line);
 }
 expression_part(RES) ::= array(A). {
        RES = A;

Simple test case:
Code:
START

{{ !(false or true or true) ? 'a' : 'b' }}

{{ -(1 + 2) }}

END

Old rendering:
PHP:
<?php
// FROM HASH: 659621440cde4d0db935d1ed0b6e9bb6
return array(
'code' => function($__templater, array $__vars, $__extensions = null)
{
    $__finalCompiled = '';
    $__finalCompiled .= 'START

' . ((!(false OR true) OR true) ? 'a' : 'b') . '

' . (-1 + 2) . '

END';
    return $__finalCompiled;
}
);

New rendering with aforementioned patch applied:
PHP:
<?php
// FROM HASH: 8dcc01353b66858d51200ddeaf4aaf62
return array(
'code' => function($__templater, array $__vars, $__extensions = null)
{
    $__finalCompiled = '';
    $__finalCompiled .= 'START

' . ((!((false OR true) OR true)) ? 'a' : 'b') . '

' . (-(1 + 2)) . '

END';
    return $__finalCompiled;
}
);
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.12).

Change log:
Adjust template Parser to allow for more precise parentheses placement in some previously ambiguous usages.
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom