diff options
-rw-r--r-- | phpBB/phpbb/template/twig/lexer.php | 8 | ||||
-rw-r--r-- | tests/template/template_test.php | 2 | ||||
-rw-r--r-- | tests/template/templates/define.html | 9 |
3 files changed, 14 insertions, 5 deletions
diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 7ab569313c..22e2c4ed3e 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -229,18 +229,18 @@ class phpbb_template_twig_lexer extends Twig_Lexer { $inner = $matches[2]; // Replace $TEST with definition.TEST - $inner = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $inner); + $inner = preg_replace('#(\s\(?!?)\$([a-zA-Z_0-9]+)#', '$1definition.$2', $inner); // Replace .foo with loops.foo|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', ' loops.$1|length$2', $inner); + $inner = preg_replace('#(\s\(?!?)\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', '$1loops.$2|length$3', $inner); // Replace .foo.bar with foo.bar|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', ' $1|length$2', $inner); + $inner = preg_replace('#(\s\(?!?)\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', '$1$2|length$3', $inner); return "<!-- {$matches[1]}IF{$inner}-->"; }; - return preg_replace_callback('#<!-- (ELSE)?IF((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#', $callback, $code); + return preg_replace_callback('#<!-- (ELSE)?IF((.*) \(?!?[\$|\.]([^\s]+)(.*))-->#', $callback, $code); } /** diff --git a/tests/template/template_test.php b/tests/template/template_test.php index f2e3903458..bd5d997c09 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -158,7 +158,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?\n[]", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?[]", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index e6c8ef49c9..8405ea55fb 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,6 +7,15 @@ $VALUE != 'abc' <!-- ELSEIF $VALUE == 'abc' --> $VALUE == 'abc' <!-- ENDIF --> +<!-- IF ($VALUE == 'abc') --> +($VALUE == 'abc') +<!-- ENDIF --> +<!-- IF !$DOESNT_EXIST --> +!$DOESNT_EXIST +<!-- ENDIF --> +<!-- IF (!$DOESNT_EXIST) --> +(!$DOESNT_EXIST) +<!-- ENDIF --> <!-- INCLUDE define_include.html --> {$INCLUDED_VALUE} {$VALUE} |